In some cases, I found that it's useful to have highlight_string format <code>...</code> inline as part of a paragraph, and other times, as a block for demonstrating multiple lines of code. I made this function to help out.
<?php
function highlight_code($code, $inline=false, $return=false) {
(string) $highlight = "";
if ( version_compare(phpversion(), "4.2.0", "<") === 1 )
{
ob_start(); highlight_string($code);
$highlight = ob_get_contents(); ob_end_clean(); }
else
{
$highlight=highlight_string($data, true);
}
if ( $inline === true )
$highlight=str_ireplace("<code>","<code class=\"inline\">",$highlight);
else
$highlight=str_ireplace("<code>","<code class=\"block\">",$highlight);
if ( $return === true )
{
return $highlight;
}
else
{
echo $highlight;
}
}
?>