I has an array :
$phone_number = array ( 'phone' => '01219104579',
'phone' => '01219104579@abc.
'phone' => '+8401219101219',
'phone' => '01219104579/01219104479',
'phone' => '841219104579@abc.com',
'phone' => 'abcd01219104579@abc.com',
'phone' => 'Hồ2101219104579@abc.com'
);
I need to replace all Phone NO prefix (0121 or 121) with new number prefix (072 or 72):
$phone_number = array ( 'phone' => '0729104579',
'phone' => '0729104579@abc.com',
'phone' => '+840729101219',
'phone' => '0729104579/0729104479',
'phone' => '84729104579@abc.com',
'phone' => 'abcd0729104579@abc.com',
'phone' => 'Hồ210729104579@abc.com' );
I tried to use PREG_REPLACE But i have problem with 8401219101219, number change to 84072910729. It should be 840729101219
How should I update all Phone NO using PHP
This code will do what you want. I'm presuming you actually want to replace
0121
or121
with072
or72
since that's what your sample data shows. If you really want to replace122
, just change121
to122
in the regex below:Output: