mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 16:06:15 +00:00
Fix duplicate + into formatted phones numbers and make localePrefix phonenumber regex as a static table
This commit is contained in:
parent
38d0cea3df
commit
c5a9324305
@ -34,10 +34,14 @@ class PhoneNumberFormatter {
|
||||
'#^(00|\+)(9[0|1|2|3|4|5|8])#' // +9x
|
||||
);
|
||||
|
||||
public static $localPrePhoneNumber_rxp = array(
|
||||
'#(^0)([^0])#' // in germany : 0-xx[x[x]]-123456
|
||||
); //
|
||||
|
||||
public static function format ($country, $pn) {
|
||||
// If no country or country not found into mapper, return false
|
||||
// If no country or country not found into mapper, return original number
|
||||
if ($country === false || !array_key_exists($country, CountryCodes::$codes)) {
|
||||
return $pn;
|
||||
return trim($pn);
|
||||
}
|
||||
|
||||
$ignrxp = array( // match non digits and +
|
||||
@ -52,19 +56,13 @@ class PhoneNumberFormatter {
|
||||
''
|
||||
);
|
||||
|
||||
/*
|
||||
@TODO: make local settings in web-page
|
||||
*/
|
||||
$lpnrxp = array( // match local numbers
|
||||
'#(^0)([^0])#' // in germany : 0-xx[x[x]]-123456
|
||||
); //
|
||||
$lpnrpl = CountryCodes::$codes[$country].'$2'; // replace with +{countryCode} -xx[x[x]]-123456
|
||||
|
||||
$lpnrpl = '+'.CountryCodes::$codes[$country].'$2'; // replace with +{countryCode} -xx[x[x]]-123456
|
||||
$tpn = trim($pn);
|
||||
|
||||
if (preg_match('#^[\d\+\(\[\{].*#',$tpn)) { // start with digit, +, (, [ or {
|
||||
$fpn = preg_replace($ignrxp, $ignrpl, $tpn); // replace everything but digits/+ with ''
|
||||
$xpn = preg_replace($lpnrxp, $lpnrpl, $fpn); // replace local prenumbers
|
||||
$xpn = preg_replace(PhoneNumberFormatter::$localPrePhoneNumber_rxp, $lpnrpl, $fpn); // replace local prenumbers
|
||||
$ypn = preg_replace(PhoneNumberFormatter::$intlPhoneNumber_rxp, '+$2', $xpn); // format to international coding +x[x[x]].....
|
||||
} else {
|
||||
$ypn = $tpn; // some SMS_adresses are strings
|
||||
|
Loading…
x
Reference in New Issue
Block a user