很多地方为了隐藏用户名信息,用*星号代替。

可以封装成方法直接处理。

function hideStar($str) { //用户名、邮箱、手机账号中间字符串以*隐藏

if (strpos($str, '@')) {

$email_array = explode("@", $str);

$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($str, 0, 3); //邮箱前缀

$count = 0;

$str = preg_replace('/([\d\w+_-]{0,100})@/', '***@', $str, -1, $count);

$rs = $prevfix . $str;

} else {

$pattern = '/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i';

if (preg_match($pattern, $str)) {

$rs = preg_replace($pattern, '$1****$2', $str); // substr_replace($name,'****',3,4);

} else {

$rs = substr($str, 0, 3) . "***" . substr($str, -1);

}

}

return $rs;

}

?>

手机号码规则没有更新,可以百度下最新的手机号码规则

 

文章来源:刘俊涛的博客

地址:http://www.cnblogs.com/lovebing

相关文章:

  • 2022-12-23
  • 2021-08-20
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2022-02-08
猜你喜欢
  • 2022-01-16
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2021-09-07
  • 2021-11-19
相关资源
相似解决方案