From f9b6555f54fc382deaf43a90e169b005afe9e671 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Fri, 30 Aug 2024 15:23:33 +0300 Subject: [PATCH] =?utf8?q?[ERP-166]=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20?= =?utf8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BE=D1=87=D0=B8=D1=81=D1=82?= =?utf8?q?=D0=BA=D0=B8=20=D1=82=D0=B5=D0=BB=D0=B5=D1=84=D0=BE=D0=BD=D0=BD?= =?utf8?q?=D1=8B=D1=85=20=D0=BD=D0=BE=D0=BC=D0=B5=D1=80=D0=BE=D0=B2=20?= =?utf8?q?=D1=81=D0=BE=20=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BE=D1=87=D0=BD?= =?utf8?q?=D0=B8=D0=BA=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/helpers/ClientHelper.php | 53 +++++++++++++--------------------- 1 file changed, 20 insertions(+), 33 deletions(-) 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; } -- 2.39.5