highlighting of php code. At my web log / rant site, I'm creating / have created a couple
of features to help facilitate rantings, addition of links (dictionary and jargon filters), a bad word filter, and now, a filter to highlight included code. It works great except for the issue of double and single quotes. This isn't an issue where add and strip slashes is going to do any good.
Anyways, this board does a wonderful job of it, does anyone know what it's doing?
Here is mine.
Code: Select all
<?php
# The idea of this filter is to take some <php> tags and replace them with highlighted code in a table
function php_filter($string)
{
$table_open="<table border="0" width="70%"><tr><td bgcolor="white"><?\n";
$table_close="\n?></td></tr></table>";
$str_array1=explode("\n", $string);
unset($string);
$new_string='';
$x=sizeof($str_array1);
$y=0;
$write_flag='s';
$buffer=array();
$n=0;
for($y=0; $y<$x; ++$y)
{
if(strstr($str_array1[$y], '<php>'))
{ $write_flag='y'; }
if($write_flag=='y')
{ @$buffer[$n].=$str_array1[$y]."\n"; }
if(strstr($str_array1[$y], '</php>'))
{
$buffer[$n]=str_replace('<php>', $table_open, $buffer[$n]);
$buffer[$n]=str_replace('</php>', $table_close, $buffer[$n]);
$buffer[$n]=@highlight_string($buffer[$n], true);
$buffer[$n]=str_replace("<code><font color="#000000">", "", $buffer[$n]);
$buffer[$n]=str_replace("</code>", "", $buffer[$n]);
$buffer[$n]=str_replace("<", "<", $buffer[$n]);
$buffer[$n]=str_replace(">", ">", $buffer[$n]);
$write_flag='append';
}
if($write_flag=='n' || $write_flag=='s')
{ $new_string.=$str_array1[$y]; }
elseif($write_flag=='append')
{
$new_string.=$buffer[$n];
$write_flag='n';
++$n;
}
}
return $new_string;
}
?>The function can probably be optimized or re-thought in certain areas, but for now, I need to get this issue sussed out.
So if anyone has had any experience with this, let me know. I would really appreciate it.
Cheers,
BDKR