From: Alexander Smirnov Date: Fri, 30 Aug 2024 12:23:33 +0000 (+0300) Subject: [ERP-166] новый метод очистки телефонных номеров со справочником X-Git-Tag: 1.5~27^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=f9b6555f54fc382deaf43a90e169b005afe9e671;p=erp24_rep%2Fyii-erp24%2F.git [ERP-166] новый метод очистки телефонных номеров со справочником --- diff --git a/erp24/helpers/ClientHelper.php b/erp24/helpers/ClientHelper.php index c2ecb6ea..7452fec8 100644 --- a/erp24/helpers/ClientHelper.php +++ b/erp24/helpers/ClientHelper.php @@ -13,45 +13,32 @@ class ClientHelper { } 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; }