// Highlight any code...
function highlight_php_code($code)
{
global $context;
// Remove special characters.
$code = un_htmlspecialchars(strtr($code, array('
', "\t", '['), array("\n", 'SMF_TAB();', '['), $code));
// It's easier in 4.2.x+.
if (version_compare(PHP_VERSION, '4.2.0') == -1)
{
ob_start();
highlight_string($code);
$buffer = str_replace(array("\n", "\r"), '', ob_get_contents());
ob_end_clean();
}
else
$buffer = str_replace(array("\n", "\r"), '', highlight_string($code, true));
// Yes, I know this is kludging it, but this is the best way to preserve tabs from PHP :P.
$buffer = preg_replace('~SMF_TAB(?:</(?:font|span)><(?:font color|span style)="[^"]*?">)?\\(\\);~', '<pre style="display: inline;">' . "\t" . '', $buffer);
return str_replace(array('\'', '<code>', '</code>'), array(''', '', ''), $buffer);
}
// Highlight any code...
function highlight_php_code($code)
{
global $context;
// Remove special characters.
$code = un_htmlspecialchars(str_replace(array('
', "\t", '['), array("\n", 'SMF_TAB();', '['), $code));
// It's easier in 4.2.x+.
if (version_compare(PHP_VERSION, '4.2.0') == -1)
{
ob_start();
highlight_string($code);
$buffer = str_replace(array("\n", "\r"), '', ob_get_contents());
ob_end_clean();
}
else
$buffer = str_replace(array("\n", "\r"), '', highlight_string($code, true));
// Yes, I know this is kludging it, but this is the best way to preserve tabs from PHP :P.
$buffer = preg_replace('~SMF_TAB(?:</(?:font|span)><(?:font color|span style)="[^"]*?">)?\\(\\);~', '<pre style="display: inline;">' . "\t" . '', $buffer);
return str_replace(array('\'', '<code>', '</code>'), array(''', '', ''), $buffer);
}