如何在php代码点火器中比较有国家代码和没有国家代码的手机号码


how to compare mobile number with country code and without country code in php codeigniter

如何在php 中比较手机号码

例如,

第一个数字是9999999999和第二个数字是+9919999999999

现在如何匹配这2个数字是相等还是不相等。

假设所有手机号码都是10位数(到目前为止,我还没有遇到任何不是10位数的),那么比较这两个字符串的最后10个字符不是更容易吗?

http://php.net/manual/en/function.substr-compare.php

您可以使用preg_replace函数将初始+99替换为0099作为国际预选或0作为国家预选然后将其与手机号码进行比较。

$pattern='|('+)(('d{2})('d+))|';
//comment that $replace, you don't want to use
$replace='00$3$4'; //replaces initial +49 with 0049 (international pre selection)
$replace='0$4'; //replaces initial +49 with 0 (national pre selection)
$tel="+49163 1234567";
$tel_clean=preg_replace($pattern,$replace,$tel);

关于