highlight_file with CSS classes, line numbers, and   replaced

this page lists itself

001
<style type="text/css">.aw_default {color:blue} .aw_keyword{color:green}  .aw_comment{color:brown;font-weight:bold} .aw_string{color:red} .aw_htmlsrc{color:black;}  .linenum{font-weight:normal !important; border-right:1px solid grey;color:black;text-align:right;padding:0 0.2em;margin-right:0.5em;}</style><h3>highlight_file with CSS classes, line numbers, and &amp;nbsp; replaced</h3><h3>this page lists itself</h3><pre><?php/* tricks highlight_file into using CSS classes and  adds line numbers to output    NOT THOROUGHLY TESTED - USE AT YOUR OWN RISK  Author: Andy Wrigley (http://means.us.com)*//* for explanation of injecting classes seehttp://wptest.means.us.com/2012/06/php-tricking-highlight_file-to-use-css-classes-instead-of-inline-styles/ */ini_set('highlight.default', '"class="aw_default'); ini_set('highlight.keyword','"class="aw_keyword'); ini_set('highlight.string', '"class="aw_string'); ini_set('highlight.html', '"class="aw_htmlsrc');ini_set('highlight.comment', '"class="aw_comment');# Run the PHP syntax highlighter on our file and return as string$aw_source = highlight_file('list_code_linenum_classes_nonbsp.php', TRUE);# remove stuff that affects our formating$aw_source = str_replace('<code>', '' , $aw_source );$aw_source = str_replace(array("\r\n","\r","\n"),'',$aw_source);$aw_source = trim($aw_source);# Remove empty inline styles$aw_source = str_replace('', '' , $aw_source );# you should DELETE NEXT LINE if returned string is NOT used within pre tag$aw_source = str_replace("&nbsp;", ' ', $aw_source);# use <br /> as the separator to explode $aw_source into an array$aw_source = str_replace('<br /></span>', '</span><br />' , $aw_source );$aw_lines = explode("<br />", $aw_source);# print our source listingecho "<code>";$i = 1;foreach ($aw_lines as $aw_line){  #insert line num as 3 digits with leading 0s  $line_disp = '<span class="linenum">' . sprintf("%03d",$i) .'</span>';  $line_disp .=  $aw_line;  echo $line_disp . "<br />";# $the_html .= '<span style="color:red">&lt;!-- line ' . $i . ' --&gt;</span>' . htmlentities($line_disp) . '&lt;br /&gt;<br />';$i++; } # echo "<br /><br /><h3>for copy and paste</h3><pre>&lt;code&gt;<br />" . $the_html . '</pre>';/* UNCOMMENT LINEs 40 and 42 if you also wish to display HTMLfor the listing. Use it to copy complete listing or snippetsinto other pages or "post editors" like Wordpress. */?></pre><h2>Brought to you by <a href="means.us.com">means.us.com</a></h2>

Brought to you by means.us.com