php 用星号*替换手机号码的几种方法
最编程
2024-03-20 11:42:42
...
通过php用三种简单的方法实现手机号中间四位(n位)用星号显示:
1.substr字符串截取法
$mobile = '13912345678';
$newMobile1 = substr($mobile, 0, 5).'****'.substr($mobile, 9);
echo $newMobile1.'<br/>';
2.substr_replace替换字符串的子串
$newMobile2 = substr_replace($mobile, '****', 5, 4);
echo $newMobile2.'<br/>';
3.preg_replace正则法
$newMobile3 = preg_replace('/(\d{5})\d{4}(\d{2})/', '$1****$2', $mobile);
echo $newMobile3;
下一篇: CVE-2020-1350 详情和复制