Andrew, yes that's it what I was doing when I couldn't get it to work properly. The only problem of the regexp is the replacement part.
PHPJohn that was a copy & paste error.
I have now found the solution: I created a second function and pass the captured results as arguments to this function:
PHP Code:
function convert($class, $text) {
// to be used with with the /e switch later
static $search = array(
'000000' => '',
'FF9900' => 'comment',
'007700' => 'syntax1',
'0000BB' => 'syntax2',
'DD0000' => 'strings'
);
return '<span class="' . $search[$class] . '">' . stripslashes($text) . '</span>';
}
function php_highlight_file($filename) {
// check if the file exists
if (!file_exists($filename))
return;
// use PHP's highlight_file
$output = highlight_file($filename, 1);
$output = preg_replace(
'!<font color="#(000000|FF9900|007700|0000BB|DD0000)">(.+?)</font>!ise',
"convert('$1', '$2')",
$output);
return $output;
}
Bookmarks