PHP手机号中间四位用星号*代替显示的实例
在显示用户列表的场景中,一般用到手机号的显示时都需要对手机号进行处理,一般是把中间的四位换成星号****,我本人用php处理的思路是进行替换,用****替换手机号的中间四位
代码如下:
$all_lottery_logs = ********; //该语句是得到中奖纪录 //遍历处理手机号 foreach($all_lottery_logs as $k=>$v){ $xing = substr($v['tel'],3,4); //获取手机号中间四位 $all_lottery_logs[$k]['tel'] = str_replace($xing,'****',$v['tel']); //用****进行替换 }
另外几种方法
<?php $tel = '12345678910'; //1.字符串截取法 $new_tel1 = substr($tel, 0, 3).'****'.substr($tel, 7); var_dump($new_tel1); //2.替换字符串的子串 $new_tel2 = substr_replace($tel, '****', 3, 4); var_dump($new_tel2); //3.用正则 $new_tel3 = preg_replace('/(\d{3})\d{4}(\d{4})/', '$1****$2', $tel); var_dump($new_tel3); ?>
结果:
> string(11) "123****8910" > string(11) "123****8910" > string(11) "123****8910"
相关推荐
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23