I’m using a date converter PHP function which worked with preg_replace in PHP 5.x.
Now after the PHP 7.x update I can’t use the code due to error:
preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead.
The code is:
$pattern=array(
"#Y#",//full year
"#y#",//short year
"#M#",//month short name
"#F#",//month full name
"#m#",//month number 0 lead
"#n#",//month number
"#t#",//days in month
"#l#",//full week day
"#D#",//short week day
"#d#",//day number of month
"#j#",//day number of month
"#a#",//AM/PM short view
"#A#",//AM/PM full view
"#([^yYMmDdAa])#e"
);
$replace=array(
$d->ENnum2FA($converted[0]),//year 13xx
$d->ENnum2FA(substr($converted[0],2),true),//year xx lead zero
$d->shmonths[$converted[1]],//month name
$d->months[$converted[1]],//month name
$d->ENnum2FA($converted[1],true), //month number
$d->ENnum2FA($converted[1]), //month number
//$converted[1],
$d->j_days_in_month[$converted[1]],
$d->days[strtolower(gmdate("D",$stamp))],//week day {full view}
$d->ldays[strtolower(gmdate("D",$stamp))],//week day {short view}
$d->ENnum2FA($converted[2],true),//day of month
$d->ENnum2FA($converted[2],true),//day of month
$d->pmam[gmdate('a',$stamp)],
$d->pmam[gmdate('A',$stamp)],
"\$d->ENnum2FA(gmdate('\\1',\$stamp))"
);
$date= preg_replace($pattern,$replace,$format);
I used this link’s solution:
I made the following changes:
1. "#([^yYMmDdAa])#e" ===> "#([^yYMmDdAa])#
2. "\$d->ENnum2FA(gmdate('\\1',\$stamp))" ===> "\$d->ENnum2FA(gmdate('\$match[1]',\$stamp))"
3. $date= preg_replace($pattern,$replace,$format); ===> $date=preg_replace_callback($pattern, function($match) {
return $replace;
}, $format);
Finally the code became:
$pattern=array(
"#Y#",//full year
"#y#",//short year
"#M#",//month short name
"#F#",//month full name
"#m#",//month number 0 lead
"#n#",//month number
"#t#",//days in month
"#l#",//full week day
"#D#",//short week day
"#d#",//day number of month
"#j#",//day number of month
"#a#",//AM/PM short view
"#A#",//AM/PM full view
"#([^yYMmDdAa])#"
);
$replace=array(
$d->ENnum2FA($converted[0]),//year 13xx
$d->ENnum2FA(substr($converted[0],2),true),//year xx lead zero
$d->shmonths[$converted[1]],//month name
$d->months[$converted[1]],//month name
$d->ENnum2FA($converted[1],true), //month number
$d->ENnum2FA($converted[1]), //month number
//$converted[1],
$d->j_days_in_month[$converted[1]],
$d->days[strtolower(gmdate("D",$stamp))],//week day {full view}
$d->ldays[strtolower(gmdate("D",$stamp))],//week day {short view}
$d->ENnum2FA($converted[2],true),//day of month
$d->ENnum2FA($converted[2],true),//day of month
$d->pmam[gmdate('a',$stamp)],
$d->pmam[gmdate('A',$stamp)],
"\$d->ENnum2FA(gmdate('\$match[1]',\$stamp))"
);
$date=preg_replace_callback($pattern, function($match) {
return $replace;
}, $format);
But nothing happens. I think it’s because of array inputs. How can I solve it?