Beispiel für die Anwendung von highlight_string():
<?php
function php_string($text){
$text = stripslashes($text);
ob_start();
highlight_string($text);
$text = ob_get_contents();
ob_end_clean();
return $text;
}
$text = '
PHP-Code:
<?php echo "Hallo!" ?>
';
$text = preg_replace("/\[php\](.*)\[\/php\]/esiU", "php_string('$1')", $text);
echo $text;
?>