菜单

PHP uses regular expressions to implement cell phone numbers, the middle 4 bits with asterisk (*) replace display function

2017年11月22日 - PHPer

Because of the need to maintain the privacy of customers, so the mobile phone number can not be fully displayed on the website, but it is not that so many sites that display but not complete, in the above with an asterisk replacing part of the show, in fact, do this is very simple, with the regular replacement of a part can be displayed.

Method 1:

Function hidtel ($phone) {

($IsWhat = preg_match / (0[0-9]{2,3}[\-]? [2-9][0-9]{6,7}[\-]? [0-9]? /i’), $phone); / / fixed telephone

If ($IsWhat = = 1) {

Return (preg_replace / (0[0-9]{2,3}[\-]? [2-9]) [0-9]{3,4} ([0-9]{3}[\-]? [0-9]? /i’),’$1****$2′, $phone);

}else{

Return (preg_replace / (1[358]{1}[0-9]) [0-9]{4} ([0-9]{4}) /i’,’$1****$2′, $phone);

}

}

Method 2:

$num = “13966778888””

$str = substr_replace ($num,’****’, 3,4);

Examples:

$phonenum = “13966778888””;

Echo hidtel ($phonenum);

Final output: 139****8888

发表评论

电子邮件地址不会被公开。