php如何实现手机号脱敏(隐藏手机号中间4位)

2025年01月24日 建站教程

具体代码如下:

function hidePhoneNumber($phoneNumber) {
  $result = "";
  //判断手机号是否正确
  if(preg_match("/1\d{10}/", $phoneNumber)){
    //使用substr_replace将中间四位替换为*
    $result = substr_replace($phoneNumber, '****', 3, 4);
  }
  return $result;
}

本文链接:http://so.lmcjl.com/news/21941/

展开阅读全文
相关内容