This is was the same function I use to syntax highlight all of my code at this site. There's a lot of syntax highlighters out there, but I settled on the google-code-prettify because it is lightweight, customizable, simple, and developed and used by Google themselves. As always, Internet Explorer did their best to screw up the code, and this function addresses the fix by prefixing every newline with ' ' (an XML friendly ' ') for you.

This function will syntax highlight your code using google-code-prettify.

$code The code you want to syntax highlight.
$lang The language, if you want to specify it. This is completely optional. The avaliable values are 'bsh', 'c', 'cc', 'cpp', 'cs', 'csh', 'cyc', 'cv', 'htm', 'html', 'java', 'js', 'm', 'mxml', 'perl', 'pl', 'pm', 'py', 'rb', 'sh', 'xhtml', 'xml', and 'xsl'.
$linenum Set to true if you want the lines to be numbered. If your code doesn't begin on line 1 then you can indicate here where it does, and your code will be numbered accordingly.
Returns Your code in a <pre> tag that will be syntax highlighted when the page has loaded.
$html .= prettify('<?php  
echo 'Syntax Highlighted Code';