What I did wrong? It still returns 21-11-2016
.
$string = '21-11-2016';
$pattern = '/({0-9}(2))-({0-9}(2))-({0-9}(4))/';
$rep = "Month: $2 , Day: $1 , Year: $3";
echo preg_replace($pattern, $rep, $string);
die();
What I did wrong? It still returns 21-11-2016
.
$string = '21-11-2016';
$pattern = '/({0-9}(2))-({0-9}(2))-({0-9}(4))/';
$rep = "Month: $2 , Day: $1 , Year: $3";
echo preg_replace($pattern, $rep, $string);
die();
You have {..}
and (..)
at wrong place. Use:
echo preg_replace('/([0-9]{2})-([0-9]{2})-([0-9]{4})/', $rep, $string);
{...}
makes it a range and [...]
makes it a character class.