I have below a simple (BBCode) PHP code for insert code into a comment/post.
function highlight_code($str) {
$search = array(
'/\[code=(.*?),(.*?)\](((?R)|.)*?)\[\/code\]/is',
'/\[quickcode=(.*?)\](((?R)|.)*?)\[\/quickcode\]/is'
);
$replace = array(
'<pre title="$2" class="brush: $1;">$3</pre>',
'<pre class="brush: $1; gutter: false;">$2</pre>'
);
$str = preg_replace($search, $replace, $str);
return $str;
}
What I want to be able to do is insert functions at these locations:
$replace = array(
'<pre title="$2" class="brush: $1;">'.myFunction('$3').'</pre>',
^here
'<pre class="brush: $1; gutter: false;">'.myFunction('$2').'</pre>'
^here
);
From what I've read on SO I may need to use preg_replace_callback()
or an e-modifier, but I cannot figure out how to go about doing this; my knowledge with regex is not so good. Would appreciate some help!