I have some code with the a structure similar to this
function bbcode($Text)
{ //$Text = preg_replace(\"/\\[video\\](.+?)\\[\\/video\\]
try preg_replace_callback
return preg_replace_callback("/\[video\](.+?)\[\/video\]/", 'embed_video', $Text);
function embed_video($matches)
{
return $matches[1] . 'foo';
}
You can use the "e" modifier on preg_replace()
(see Pattern Modifiers)
return preg_replace("/\[video\](.+?)\[\/video\]/e", "embed_video('$1')", $Text);
which tells preg_replace()
to treat the second parameter as PHP code.