Автоматическая подсветка PHP кода в тексте.
<?php
$text = htmlspecialchars('[code]
echo\' ky\';[/code]', ENT_QUOTES, 'UTF-8');
function highlight_code1($code)
{
$code = trim($code[1]);
if(!preg_match('#^<\?(.+?)\?>$#', $code))
$code='<?php
'.$code.'
?>';
return $code;
}
function highlight_code2($code)
{
return str_replace(' ', ' ', highlight_string(html_entity_decode($code[0], ENT_QUOTES, 'UTF-8'),1));
}
$text = preg_replace_callback('#\[code\](.+?)\[/code\]#sui' , 'highlight_code1', $text);
$text = preg_replace_callback('#<\?(.+?)\?>#sui', 'highlight_code2', $text);
echo $text;
?>