I would like to replace anything between {{ }}
with it's PHP date()
equivalent. So, for instance:
$path = '/some/path/{{m.d.Y}}.txt'
Would be:
$path = '/some/path/02.25.2018.txt'
How could I do this, assuming I need to use a regular expression?
I would like to replace anything between {{ }}
with it's PHP date()
equivalent. So, for instance:
$path = '/some/path/{{m.d.Y}}.txt'
Would be:
$path = '/some/path/02.25.2018.txt'
How could I do this, assuming I need to use a regular expression?
You could use preg_replace_callback()
:
$path = '/some/path/{{m.d.Y}}.txt' ;
$path = preg_replace_callback('~({{[\w.]+}})~', function($matches) {
return date(trim($matches[0],'{}'));
}, $path);
echo $path ; // /some/path/02.25.2018.txt