jinjindandan

手机号替换为星号

//方法1-正则
$str = '15864236586';
$pattern = '/(\d{2})(\d{7})(\d{2})/i';
$a = preg_match($pattern,$str);
$replacement = '$1*******$3';
$resstr = preg_replace($pattern, $replacement,$str);
echo $resstr;

//方法2-字符串截取
$str = '15864236586';
$new_str = substr($str,0,2).'*******'.substr($str,-2);
echo $new_str;

posted on 2023-05-12 13:34  %简简单单%  阅读(42)  评论(0编辑  收藏  举报

导航