calling function inside preg_replace thats inside a function calling function inside preg_replace thats inside a function php php

calling function inside preg_replace thats inside a function


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.