php隐藏手机号的方法:1、字符串截取法,代码为【$new_1=substr($tel, 0, 3).'****'.substr($tel, 7)】;2、替换字符串的子串,代码为【$new=substr_replace($tel,)】。

php隐藏手机号的方法:
$num = "12345678910"
$str = substr_replace($num,'****',3,4);

使用官方Model Context Protocol PHP SDK将PHP应用程序功能暴露为MCP工具、资源和提示,用于代理工作流。
三种实现方式
<?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免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!










