public static function format($country, $pn)
{
// If no country or country not found into mapper, return original number
if ($country === false || !array_key_exists($country, CountryCodes::$codes)) {
return trim($pn);
}
$ignrxp = array('#[^\\d\\+\\(\\)\\[\\]\\{\\}]#', '#(.+)([\\(\\[\\{]\\d*[\\)\\]\\}])#', '#[^\\d\\+]#');
$ignrpl = array('', '$1', '');
$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(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
}
return $ypn;
}