首页 > 代码库 > 任一情况下的各种电话号码替换
任一情况下的各种电话号码替换
function filterMobile($str)
{
$num1Arr = array(‘零‘=>0,‘一‘=>1,‘二‘=>2,‘三‘=>3,‘四‘=>4,‘五‘=>5,‘六‘=>6,‘七‘=>7,‘八‘=>8,‘九‘=>9);
$num2Arr = array(‘零‘=>0,‘壹‘=>1,‘贰‘=>2,‘叁‘=>3,‘肆‘=>4,‘伍‘=>5,‘陆‘=>6,‘柒‘=>7,‘捌‘=>8,‘玖‘=>9);
$str = strtr($str, $num1Arr);
$str = strtr($str, $num2Arr);
//()¥
$str = preg_replace("/[\,\.\/\;\‘\<\>\?\:\"\|\`\~\!\@\#\$\%\^\&\*\(\)\-\=\_\+\,\。\、\《\》\?\·\~\!\#\%\……\&\*\——\+\-\=\|\ ]/is", ‘‘, $str);
preg_match_all("/[0-9]{8,11}/is", $str, $match[0]);
foreach ($match[0][0] as $val)
{
$rep = ‘‘;
$len = strlen($val);
$repStr = substr($val,0,3);
for ($i = 1; $i <= $len - 3; $i++)
{
$rep .= ‘*‘;
}
$replaceStr = $repStr.$rep;
$str = preg_replace("/$val/is", $replaceStr, $str);
}
return $str;
}
$str = ‘1变量算大我们一,2..34$$$5&&6... ^..7++ 89 0 打打我12壹54348!@%^90们阿达就卡‘;
echo filterMobile($str);
最后输出的结果:
1变量算大我们123*******打打我121*******们阿达就卡