For a decent and standardized php function I want to format a user inputted string to a std. international phone number format. The string will be stripped from other characters as digits and +-signs. All spaces will be deleted. After that I want to format the different strings to a standardized form:
+310612345678 -> +31 (0)61 234 5678
00310612345678 -> +31 (0)61 234 5678
+31612345678 -> +31 (0)61 234 5678
//add a leading zero between brackets (0))
0031612345678 -> +31 (0)61 234 5678
06 12345678 -> +31 (0)61 234 5678
//When no country code is given (no 00xx or +xx) than add the dutch one.
职能是:
function formatPhoneNumber($num){
//delete everything except digits and +
$number = preg_replace( /[^d|+]/ , , $number);
if(substr($number,0,1) == + || substr($number, 0,2) == 00){
//
}else{
$number = "+31".$number;
}
/////////
// formatting as mentioned above
/////////
return $num
}
I m 看一算法,将用户输入电话号码的不同方式格式改为一个格式:+31(0)61 2345678