任一情況下的各種電話號碼替換

來源:互聯網
上載者:User

標籤:io   for   ar   cti   amp   return   on   ip   

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壹[email protected]%^90們阿達就卡‘;
echo filterMobile($str);

 

最後輸出的結果:

1變數算大我們123*******打打我121*******們阿達就卡

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.