I'm trying to convert a javascript date format (example 'dd/mm/yy') to the PHP equivilent (example 'd/m/Y'). This is for use with the jQuery datepicker UI.
I found a function (untested) to do it the other way round, here.
I've altered it a bit to look like this:
function dateFormat(){
$pattern = array(
//day
'dd',
'd',
'DD',
'o',
//month
'MM',
'M',
'mm',
'm',
//year
'yy',
'y'
);
foreach($pattern as &$p)
{
$p = '/'.$p.'/';
}
$replace = array(
//day
'd', //day of the month
'j', //3 letter name of the day
'l', //full name of the day
'z', //day of the year
//month
'F', //Month name full
'M', //Month name short
'm', //numeric month leading zeros
'n', //numeric month no leading zeros
//year
'Y', //full numeric year
'y' //numeric year: 2 digit
);
return preg_replace($pattern, $replace, 'dd/mm/yy');
}
However, instead of returning the expected 'd/m/Y', I get 'j/n/Y'. I thought it'd do the replace in order; i.e. find dd before d and replace that first. What's going on?
Thanks.