Artician Home
Join Artician Login Search

Akujin's blog

avatar
  • Akujin
  • Male
  • Philadelphia, Philadelphia US
  • Status: Administrator
  • Blog Views: 15248
  • Last Seen: A day ago

All About Me

Akujin's Info
  • Joined: 08/21/06
  • Account: Artician Pro
  • Visits: 15248
  • Total Discussion Posts: 1236
  • Portfolio Count: 15 | View
  • Blog Entries Count: 35 | View
  • Favorites Received: 33
  • Watchers: 59
Professional
Personal
Social Networks
Category: Computers & Internet - Software Reviews, Tips & Tricks
Monday August 20th, 2007
I did a little bit of research and didn't find much on the topic of correct color highlighting of Here Docs. A 'Here Document' is a way of placing pure text without fear of syntax directly into the heart of a document with strict syntax rules which is basically the case with almost any scripting or programming language. In PHP the way to do this is:

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"Emotion: wink.gif;
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.

Add a Comment

You must be logged in to post a comment. Login or Join Artician, Free.

Comments

simonini
grazie Emotion: happy.gif
kman
(w/ a heavy Japanese Accent) NICE JOB! (~_~) b

Michael Kofman || Game Developer

http://www.straystudios.com/