Home > Article > Backend Development > PHP implements example code for the middle four digits of a mobile phone number to be an asterisk (*)
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);
}
}
$num = "13966778888"
$str = substr_replace($num,'****',3 ,4);
##$phonenum = "13966778888";
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!