Forum Moderators: coopster

Message Too Old, No Replies

print <<<EOF borking a site. Why?

A combo of Dreamweaver + print <<<EOF is killing my site

         

fwordboy

3:02 pm on Jun 16, 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.

coopster

3:25 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, I'm betting DW is the culprit. The syntax you see is called Heredoc [php.net].

fwordboy

5:31 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



I though as much, but I still can't work out what code it has changed exactly.

coopster

5:57 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could FTP to the site rather than use DW ;)

There must be a setting in DW that is causing that conversion to happen. You may want to pose the question in the WYSIWYG and Text Code Editors [webmasterworld.com] to see if anybody there can help. Either that or search Macromedia's site for something.

fwordboy

2:10 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



yeah that's my other option I cna sFTP through BBedit. But I'd rather use DW for everything as I prefer it. I'd really like know excatly what changes DW is making. I've posted this question in the WYSWYG forum.

Sathallrin

2:17 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



One thing to check is to make sure that the closing EOF; is all the way on the left with no whitespace before it (tabs/spaces) otherwise it will not find it.

And for your question of how print <<<EOF is helpful is if you are printing out a lot of html inside of a function that gets called more then once. Otherwise simply putting the html outside of php code works just fine.

SilverSanta

5:17 am on Jun 23, 2005 (gmt 0)

10+ Year Member



One advantage to the HEREDOC style is that variable inserts in the HTML still happen. Closing the PHP and putting out HTML will NOT do the inserts.

This works:

$stuff = 'hello, world';
print <<< HTML
<P>$stuff</P>
HTML;

fwordboy

3:51 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



fixed. Here's how.

In Dreamweaver> Preferences >Code Format there is an option to indent with 2 spaces automatically checked. Unchecking this solved everything. this was especially confusing as DW didn't appear to show any indentations and the code format looked identical with either settings so be warned.

coopster

5:22 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I figured there must be a setting in DW that was causing the issue. Glad you got it sorted!