php手机号码中间四位隐藏的方法:使用【substr_replace】代替方法,替换字符串的子串,代码为【$num = "12345678910" $str = substr_replace($num,'****',3,4)】。
php手机号码中间四位隐藏的方法:
使用substr_replace代替方法:
$num = "12345678910" $str = substr_replace($num,'****',3,4);
三种实现方式
<?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"
相关学习推荐:PHP编程从入门到精通
以上就是php手机号码中间四位如何隐藏?的详细内容,更多请关注php中文网其它相关文章!
![php中文网最新课程二维码](/static/images/article_wechat2021.jpg?1111)
声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
- 上一篇:php如何清除标签
- 下一篇:php中const define区别有哪些
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论