I have php mysql application and i want the phone numbers be saved in a specific format. after some googling i reached up to this function:
function RemoveExt($phone) {
if(substr($phone,0,1) == '+' || substr($phone, 0,2) == 00){
$phone = preg_replace('/[^\d]/', '', $phone);
}
$phone=trim($phone);
$prefixs=array('0097150','0097156','0097152','0097155', '97150','97156','97155','97152','050','056','055','052','00');
$replace=array('050','056','052','055','050','056','055','052','050','056','055','052','00');
$count = count($prefixs);
for($i = 0; $i < $count; $i++)
{
if(strncmp($phone, $prefixs[$i], strlen($prefixs[$i])) == 0){
$phone = preg_replace('/^'.$prefixs[$i].'/i','',$phone);
$ext=$replace[$i];
return array('phone' => $phone, 'ext' => $ext);
}else{
return array('phone' => $phone, 'ext' => $ext);
}
}
}
for example the phone number +971501234567 =>
“+” will be the international code,
“971” will be the country code,
“50” will be the mobile network code and
“1234567” will be the mobile number.
noted that we have more than one mobile code.
The question that I need to save two parts from the number (mobile network code, mobile number)
for example: +971501234567 will be saved as (050) the mobile network code and (1234567) the mobile number.
could anyone help me to achive that?.
I am going to share the working class :-
Hope help someone.