Вы можете использовать этот фрагмент (электронный модификатор):
<code>function highlight_code($str) {
$search = array(
'/\[code=(.*?),(.*?)\](((?R)|.)*?)\[\/code\]/ise',
'/\[quickcode=(.*?)\](((?R)|.)*?)\[\/quickcode\]/ise'
);
// these replacements will be passed to eval and executed. Note the escaped
// single quotes to get a string literal within the eval'd code
$replace = array(
'\'<pre title="$2" class="brush: $1;">\'.myFunction(\'$3\').\'
\ '', '\'
\'.myFunction(\'$2\').\'
\ '');$ str = preg_replace ($ search, $ replace, $ str);вернуть $ str;}
или этот (обратный вызов):
<code>function highlight_code($str) {
$search = array(
'/\[code=(.*?),(.*?)\](((?R)|.)*?)\[\/code\]/is',
'/\[quickcode=(.*?)\](((?R)|.)*?)\[\/quickcode\]/is'
);
// Array of PHP 5.3 Closures
$replace = array(
function ($matches) {
return '<pre title="'.$matches[2].'" class="brush: '.$matches[1].';">'.myFunction($matches[3]).'
';}, function ($ match) {return '
'.myFunction($matches[2]).'
';});// preg_replace_callback не поддерживает замены массивов.foreach ($ search as $ key => $ regex) {$ str = preg_replace_callback ($ search [$ key], $ replace [$ key], $ str);} return $ str;}