print <<< EOF
<a href="http://akujin.artician.com/blog/2007/08/Finally-Correct-Here-Doc-EOF-parsing-in-Dreamweaver-for-PHP/" title="{TITLE}"><img src="{IMAGE}" alt="{TITLE}" /></a>
EOF;
Wikipedia has a great entry explaining all about Here Documents and PHP.net explains in it's documentation under Strings.
The problem with Dreamweaver is that Macromedia's DW team overlooked syntax highlighting for the Here Docs as pure PHP and choose not to treat it differently from the rest of the PHP. In hindsight this might have been a cleaner design decision but the fact is that people use here docs and the text within a here doc is almost always not PHP and in my experience is almost always HTML or XML. Occasionally JavaScript might find it's way in there as well.
After seeing a completely custom Code Coloring XML file for Dreamweaver for the Smarty templating system I decided to poke and prod around and try to hack together a correct color coding solution for my way of doing templating on Artician which is like so:
<?php
$TEMPLATE = <<< EOF
<a href="http://akujin.artician.com/blog/2007/08/Finally-Correct-Here-Doc-EOF-parsing-in-Dreamweaver-for-PHP/" title="{TITLE}"><img src="{IMAGE}" alt="{TITLE}" /></a>
EOF;
function makeHTML() {
global $TEMPLATE;
db_q("SELECT `link`,`title`,`image` FROM table"
while($row = db_r()) {
$temp = str_replace('http://akujin.artician.com/blog/2007/08/Finally-Correct-Here-Doc-EOF-parsing-in-Dreamweaver-for-PHP/',$row['link'],$TEMPLATE);
$temp = str_replace('{TITLE}',$row['title'],$temp);
$temp = str_replace('{IMAGE}',$row['image'],$temp);
$output .= $temp;
}
return $output;
}
?>
<!-- SOME HTML -->
<?php
echo makeHTML();
?>
I've been using the above method on Artician for over a year now and all along using Dreamweaver with very unwieldy text coloring when the here doc shows up. If I had an unclosed single or double quote in the here doc then PHP would continue it, treating it like a very long string. I can of course fix this by placing a comment with a closer quote but this is just a quick hack for a problem that should not even be there in the first place.
Never the less, here's the fix:
Open: Program Files\Adobe\Adobe Dreamweaver CS3\configuration\CodeColoring\PHP.xml
(I'm not sure about Dreamweaver MX and 8 but I'd assume it would be the same.)
Go down to Line 18 and find:
<blockEnd><![CDATA[</script>]]></blockEnd>
Copy and Paste the following on the next line (Don't remove what was there, instead hit enter a few times and make room):
<blockStart doctypes="PHP_MySQL" scheme="customText"><![CDATA[<?phps]]></blockStart>
<blockEnd><![CDATA[<<<s*EOF]]></blockEnd>
<blockStart doctypes="PHP_MySQL" scheme="customText"><![CDATA[<?phpn]]></blockStart>
<blockEnd><![CDATA[<<<s*EOF]]></blockEnd>
<blockStart doctypes="PHP_MySQL" scheme="customText"><![CDATA[EOF;]]></blockStart>
<blockEnd><![CDATA[?>]]></blockEnd>
And now we've got some better looking code and Dreamweaver treats all the code inside the Here doc as if it wasn't inside of it at all.
Comments
Michael Kofman || Game Developer
http://www.straystudios.com/