Forum Moderators: open

Message Too Old, No Replies

Dreamweaver and Print <<< EOF (PHP)

Is Dreamweaver modifying these PHP scripts?

         

fwordboy

8:41 am on Jun 17, 2005 (gmt 0)

10+ Year Member



Until this week I'd never heard of print <<<EOF but my new employer's websites make heavy use of it across the board.

When I started I downloaded all the files from the server to my work Mac using Dreamweaver MX 2004 and simply edited some HTML on the odd PHP page and uploaded them back to the server once again via Dreamweaver MX 2004 but the whole page disappeared. For some reason the server didn't seem to be liking the

<?php

//loads of PHP here
print <<<EOF

<html goes here />

EOF;
//more PHP code here
?>

and when I changed it to this

<?php

//loads of PHP here

?>

<html goes here />
<?php
//more PHP code goes here
?>

Everything returned to normal. The only explanation I can think of is Dreamweaver is slightly modifying the EOF code. Could this be the case? Otherwise I am completely flummoxed. I've only been PHPing for less than a year so any help would be fantastic, also some explanations of the benefits of Print <<< EOF code would be really helpful.

fwordboy

1:21 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



anyone?

sonjay

2:23 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



That's the HEREDOC syntax --you can find more about it here [us2.php.net]

DW may be auto-indenting your code. HEREDOC requires that the beginning and ending bits have nothing (not even whitespace) on the lines "print <<<EOF" and "EOF;" other than the actual php commands and an optional return character. If DW is autoindenting your code and putting spaces in there, that would cause problems.

fwordboy

3:45 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



yeah I imagine it is indenting it but, it's not showing it; if i create a file as thus in BBEdit


<?php
print <<<eof
<html />
eof;
?>

and view it in a browser it works.
if i then open up that file in DW and save the file making changes e.g. add another line of html then the whole text between the

print <<<eof
and the
eof;
will not appear in the browser.

the file will look identical in DW and BBEdit with no extra indentation in DW whatsoever.

sonjay

5:19 pm on Jun 22, 2005 (gmt 0)

10+ Year Member



I see you've received no other responses. I have no clue what's going on with your file, but I use both php and Dreamweaver extensively on my Mac, and I'd be happy to take a look at it if you want to send it to me.

(Not sure if my email addy shows up in my profile, but you can sticky-mail me for it.)

jayANN

4:48 pm on Jul 8, 2005 (gmt 0)



I'm not sure what you're doing wrong. I use Dreamweaver here and just ran a test with the HEREDOC and it worked ok.


print <<<EOF
testing "';':"
blah
balh
balh
EOF;

The benefit of HEREDOC is the ability to output a large bit of text without having to worry about escaping ' and ".

For instance, if I have a little javascript link:


<a href="#" onclick="doThis('string')">

I'd have to escape either ' or " depending on how I started the print/variable assign.

For large chunks of text that you may want to output or assign, this can be a pain, especially if you're cutting/pasting the HTML from a 3rd party source (like an ad banner campaign for example).

That being said, I rarely use HEREDOC, mainly because I try to keep HTML code outside of the controlling PHP.

coopster

9:40 pm on Jul 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, jayANN.

Actually the issue was resolved in the original thread which redirected the OP here.

[webmasterworld.com...]