@', '', str_replace('\"', '"', $text)); // Undo the escaping in the prepare step $text = decode_entities($text); // Trim leading and trailing linebreaks $text = trim($text, "\r\n"); // Highlight as PHP $text = '
', '
', "\n"), array('', '', ''), $text);
return $text;
}
/**
* Processes chunks of escaped code into HTML.
*/
function codefilter_process_code($text) {
// Undo linebreak escaping
$text = str_replace('
', "\n", $text);
// Inline or block level piece?
$multiline = strpos($text, "\n") !== FALSE;
// Note, pay attention to odd preg_replace-with-/e behaviour on slashes
$text = preg_replace("/^\n/", '', preg_replace('@?(br|p)\s*/?>@', '', str_replace('\"', '"', $text)));
// Trim leading and trailing linebreaks
$text = trim($text, "\n");
// Escape newlines
$text = nl2br($text);
// PHP code in regular code
$text = preg_replace_callback('/<\?php.+?\?>/s', 'codefilter_process_php_inline', $text);
$text = ''. codefilter_fix_spaces(str_replace(' ', ' ', $text)) .'
';
if ($multiline) $text = '
, , [?php ?], <% %>, and [% %]
to prevent other filters from acting on them. */
$text = preg_replace('@(.+?)
@se', "codefilter_escape('$1', 'code')", $text);
$text = preg_replace('@[\[<](\?php|%)(.+?)(\?|%)[\]>]@se', "codefilter_escape('$2', 'php')", $text);
return $text;
case 'process':
$text = preg_replace('@\[codefilter_code\](.+?)\[/codefilter_code\]@se', "codefilter_process_code('$1')", $text);
$text = preg_replace('@\[codefilter_php\](.+?)\[/codefilter_php\]@se', "codefilter_process_php('$1')", $text);
return $text;
default:
return $text;
}
}