PHP 5.2.15
I am trying to replace {date[F]} with the date function.
I have the pattern which works great.
preg_replace('/({date\[(.*?)\]})/', date(${2}), $subject);
I have tried preg_replace_callback but it doesn’t seem to work even when I use create_function()
I get mostly undefined errors on my methods tried.
You do need the
/emodifier. And the replacement expression must be a string:Note that you also forgot to escape the first
{curly brace.See the manual examples for
preg_replace#105490. Or howpreg_replace_callbackcallbacks must unpack the match parameter (which sounds like your original issue).