Forum Moderators: open
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.
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.
<?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.
(Not sure if my email addy shows up in my profile, but you can sticky-mail me for it.)
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.
Actually the issue was resolved in the original thread which redirected the OP here.
[webmasterworld.com...]