rargh
ok, i had a whinge around google until i found out how to do syntax highlights for code...
and came up with this:
function syntax_hilight($filename) {
if ((substr($filename, -4) == '.php')) {
ob_start();
show_source($filename);
$buffer = ob_get_contents();
ob_end_clean();
} else {
$argv = '-q -p - -E --language=html --color '.escapeshellcmd($filename);
$buffer = array();
exec("enscript $argv", $buffer);
$buffer = join("\n", $buffer);
$buffer = eregi_replace('^.*<PRE>', '<pre>', $buffer);
$buffer = eregi_replace('</PRE>.*$', '</pre>', $buffer);
}
// Making it XHTML compatible.
$buffer = eregi_replace('<FONT COLOR="([^"]*)">',
'<span style="color:\1">', $buffer);
$buffer = eregi_replace('</FONT>', '</style>', $buffer);
return $buffer;
}
ok, now that aside... basically, everytime im dragging some text out of the database, i run this:
function htmlstrip($contenttofix){
$contenttofix = stripslashes($contenttofix);
$contenttofix = eregi_replace("\r\n\r\n","<p>","$contenttofix");
$contenttofix = eregi_replace("\r\n","<br>","$contenttofix");
}
i know that the first function in this thread is for reading files, and whinging the output with all the <font="... tags etc...
basically... what i want to do... is somehow mix the two of these functions together...
sort of like thow your average bb or vB forum does, with the [ PHP][ /PHP] tags
so... something like:
$contenttofix = eregi_replace("<code>", START-FORMATTING-WITH-COLORBITS!, $contenttofix);
$contenttofix = eregi_replace("</code>", STOP-FORMATTING-WITH-COLORBITS!, $contenttofix);
and basically make it so it only formats with enscript when the code is between the <code> and </code> tags...
does that make sence? 🙂
im expecting there to be some big evil preg_match or something somewhere... but i dunno. ;(