PHP implements example code for the middle four digits of a mobile phone number to be an asterisk (*)

零下一度
Release: 2023-03-10 16:10:02
Original
2166 people have browsed it

This article mainly introduces the PHP implementation of custom function sharing that hides the middle four digits of a mobile phone number with asterisks (*). This is a relatively common function. Friends who need it can refer to it

php Block the middle four digits of the phone number:

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


##$phonenum = "13966778888";

echo hidtel($phonenum);




Final output: 139****8888

The above is the detailed content of PHP implements example code for the middle four digits of a mobile phone number to be an asterisk (*). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template