Home  >  Article  >  Backend Development  >  PHP implements custom function sharing that hides the middle four digits of a mobile phone number with an asterisk (*), mobile phone number asterisk_PHP tutorial

PHP implements custom function sharing that hides the middle four digits of a mobile phone number with an asterisk (*), mobile phone number asterisk_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:18:161709browse

PHP implements custom function sharing that hides the middle four digits of a mobile phone number with an asterisk (*), mobile phone number asterisk

php blocks the middle four digits of the phone number:

Copy code The code is as follows:

Method 1:
function hidtel($phone){
$IsWhat = preg_match('/(0[0-9]{2,3}[-]?[2-9][0-9]{6,7}[-]?[0-9]?)/ i',$phone); //Landline phone
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);

Example:

Copy code The code is as follows:

$phonenum = "13966778888";
echo hidtel($phonenum);

Final output: 139****8888

php function outputs a mobile phone number and replaces the middle five digits with asterisks. How to write

function suohao($phone){
$p = substr($phone,0,3)."*****".substr($phone,8,3);
return $p ;
}

Tool for generating asterisks with the middle four digits of mobile phone numbers

That should be easy to handle. If you are familiar with Excel, you can replace the asterisk with a function here. If you are not familiar with it, you can only customize a small tool software to solve it. Contact me for customized software.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/885653.htmlTechArticlePHP implements custom function sharing that hides the middle four digits of a mobile phone number with an asterisk (*), mobile phone number asterisk PHP blocks the middle four digits of the phone number: Copy the code as follows: Method 1: fun...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn