PHP-Code:
<?php
$string = "[ php]<?php echo \"hallo\"; ?>[ /php]";
echo func::phpHighlight($string);
class func
{
// PHP Higlight CODE
function &phpHighlight($str) {
$str = preg_replace("/(\[)(php)(\])(\r\n)*(.*)(\[\/php\])/siU", "|func::highlight('\\5');|", $str);
$str = explode('|', $str);
eval("\$str[1] = $str[1];");
$str[0] = htmlentities($str[0]);
$str[2] = htmlentities($str[2]);
foreach($str as $elem) {
$result .= stripslashes($elem);
}
return $result;
}
// zugehoeriger highlight code
function highlight($code){
$code = stripslashes($code);
$code = highlight_string($code, true);
$code = explode('
', $code);
$text = '
PHP-CODE:
<div style="background-color:#e4e4e4;border:1px solid #bfbfbf;font-family:verdana;font-size:11px;text-align:left;">';
for($x=0;$x<sizeof($code);$x++) {
$text .= ($x+1).''.$code[$x].'
';
}
$text .= '</div>';
return $text;
}
}
?>
mal ne kleine highlight klasse mit Zeilen Index
sollte helfen
mfg
[edit]
oder einfacher
$string = '<?php echo "dein php code"; ?>';
echo '<textarea name="code" cols="15" rows="8">'.$string.'</textarea>';