Custom T-Shirts & Apparel · Custom Imprints · Graphic Design · Web Development
|
Getting Dreamweaver Color Coding to Work with PHP's Heredoc
Developer Quick Tip
As it sometimes happens, I needed to reinstall Windows Vista on my laptop the other day. One of the things I forgot to back up was my custom color coding for Adobe Dreamweaver. One of the big things that bugs me about the color coding is that it doesn't recognise PHP's heredoc string literal set up. A good example of this for PHP is from the Wikipedia entry on Here Document. The PHP documentation for it can be found under PHP Manual>Strings. <?php $name = "Joe Smith"; $occupation = "Programmer"; echo <<<EOF This is a heredoc section. For more information talk to $name, your local $occupation. Thanks! EOF; $toprint = <<<EOF Hey $name! You can actually assign the heredoc section to a variable! EOF; echo strtolower($toprint); ?> In this case the string '<<<EOF' starts the block and 'EOF;' ends it. You can actually use just about any text in place of the EOF. For some reason, I've always used EOM (for end of mark maybe?) The problem is that Dreamweaver thinks this is an HTML tag of some sort and the color coding gets royally messed up especially when there are quotes in the text. The solution is to change the PHP.xml file in the ColorCoding configuration folder for Dreamweaver and force it to recognize the new block of code. Here's how to do that. Open the file: Program Files\Adobe\Adobe Dreamweaver CS4\configuration\CodeColoring\PHP.xml Note: depending on your operating system (I use Windows Vista) you may need to save the new file somewhere else and then move it into the correct folder. There are permissions issues sometimes in editting the file directly. Find the line (around line number 18) that reads: <blockend><!--[CDATA[</script>]]--></blockend> Add the follow lines below it: <blockStart doctypes="PHP_MySQL" scheme="customText"><![CDATA[<?php\s]]></blockStart> <blockEnd><![CDATA[<<<EOF]]></blockEnd> <blockStart doctypes="PHP_MySQL" scheme="customText"><![CDATA[<?php\n]]></blockStart> <blockEnd><![CDATA[<<<EOF]]></blockEnd> <blockStart doctypes="PHP_MySQL" scheme="customText"><![CDATA[EOF;]]></blockStart> <blockEnd><![CDATA[?>]]></blockEnd> Note that this example uses EOF as the block delimiter. If you are using something else, you need to replace the 3 references to it in the above code block. Save the editted PHP.xml file and restart Dreamweaver. Your code should look the way you expect it to. Javascript and HTML within the heredoc text will be correctly colored. I've used this trick in version of Dreamweaver since 8 all the way up to CS4. The file location may change and there may be some slightly different formats for the block starts and stops, but this should get you headed in the right direction. November 20, 2009
Comments (1) Jason Pegg
August 17, 2010
Brilliant! Thank you!
|
Valador StudiosRecent Articles |