}
public static function phoneClear($phone) {
+ $prefixes = [
+ 7 => 10, // Russia
+ 39 => 10, // Italy
+ 38 => 10, // Ukrain
+ ];
$phone = preg_replace("/[^0-9\,]/i", "", $phone);
- // $urlstr = preg_replace('/[^A-Za-z0-9_\-]/', '', $urlstr);
+ $phones = explode(",", $phone);
+ foreach ($phones as $ind => $p) {
+ if ($ind == 0) { continue; }
+ $phones[$ind] = clearPhone($p);
+ }
+ $phone = $phones[0];
$phone_str = strlen($phone);
- if ($phone_str == 10 && $phone[0] != '7') {
- $phone = "7$phone";
- } elseif ($phone_str == 11) {
- $str0 = substr($phone, 0, 1);
- if ($str0 == 8) {
- $phone = substr($phone, 1,11);
- $phone = "7$phone";
+ if ($phone_str > 1) {
+ if ($phone[0] == 8) {
+ $phone = '7' . substr($phone, 1);
}
- } elseif ($phone_str > 11) {
- $phone_arr = explode(",", $phone);
- $ph = "";
- $i = 0 ;
- foreach($phone_arr as $phone1) {
- if (!empty($phone1)) {
- $i++;
- $phone_str2 = strlen($phone1);
- if ($phone_str2 == 11) {
- $str01 = substr($phone1, 0, 1);
- if ($str01 == 8) {
- $phone1 = substr($phone1, 1,11);
- $ph .="7$phone1";
- } else {
- $ph .=$phone1;
- }
- } else {
- $ph .= "$phone1";
- }
- }
- $cnt = count($phone_arr);
- if ($i < $cnt and !empty($cnt)) {
- $ph .= ",";
+ foreach ($prefixes as $p => $cnt) {
+ if (str_starts_with($phone, $p)) {
+ $phone = $p . substr($phone, strlen($p), $cnt);
+ break;
}
}
- $phone =$ph;
- //echo"=".count($phone_arr)."=";
}
+ $phones[0] = $phone;
+ $phone = implode(',', $phones);
return $phone;
}