I have one array for data
$data = array(title=>'some title', date=>1350498600, story=>'Some story');
I have a template
$template = "#title#, <br>#date(d)#<br> #date(m)#<br>#date(Y)#<br> #story#";
All i want is to fit data into template and i know that can be done by str_replace but my problem is the date format. date format is coming from the template not from the data, in data date is stored as php date.
yesterday i tried to ask the same question but i think my question wasn’t clear.
Anybody please help me.
i think it won’t work with str_replace easily so i’m going to use preg_replace
Instead of using
date(m)ordate(Y)you could also do things likedate(d-m-Y)using this snippetThis has the disadvantage that you can format only the
datevariable using this mechanism. But with a few tweaks you can extend this functionality.Note: If you use a PHP version below 5.3 you can’t use closures but you can do the following:
You can find more information about callbacks in PHP here