/**
* 隐藏手机号中间4位
* @param $mobile
* @return string|string[]|null
*/
final protected function hideMobilePhoneNumber($mobile)
{
$IsWhat = preg_match('/(0[0-9]{2,3}[\-]?[2-9][0-9]{6,7}[\-]?[0-9]?)/i', $mobile);
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', $mobile);
} else {
$pattern = '/(\d{3})(\d{4})(\d{4})/i';
$replacement = '$1****$3';
return preg_replace($pattern, $replacement, $mobile);
}
}
正则匹配 隐藏手机号中间4位
点赞
收藏