Fejl i highlight script
Hej Alle.Jeg har fundet et php highlight script på nettet, som jeg så vil have til at replace [php]<? echo "PHP Kode!"; ?>[/php] til highlightet tekst, med linie numre. Her er koden:
// Highlight Kode
function highlight_linenum($data, $funclink = true, $return = false){
// Init
$data = explode ('<br />', $data);
$start = '<span style="color: black;">';
$end = '</span>';
$i = 1;
$text = '';
// Loop
foreach ($data as $line) {
$text .= $start . $i . ' ' . $end .
str_replace("\n", '', $line) . "<br />\n";
++$i;
}
// Optional function linking
if ($funclink === true) {
$keyword_col = ini_get('highlight.keyword');
$manual = 'http://www.php.net/function.';
$text = preg_replace(
// Match a highlighted keyword
'~([\w_]+)(\s*</span>)'.
// Followed by a bracket
'(\s*<span\s+style="color: ' . $keyword_col . '">\s*\()~m',
// Replace with a link to the manual
'<a href="' . $manual . '$1">$1</a>$2$3', $text);
}
// Return mode
if ($return === false) {
echo $text;
} else {
return $text;
}
}
$tekst = eregi_replace("\\[php\\]([^\\[]*)\\[/php\\]", "<div class=\"code\"><? highlight_linenum('\\1'); ?></div>",$tekst);
Den udskriver godt nok: <? highlight_linenum('PHP Kode'); ?>, men det er ligesom at mit php dokument ikke tager fat i det. Den registrerer det ikke. Hvorfor?
På forhånd tak for hjælpen.
