PHP可以实现类似某些网站将用户名中间部分字符信息用 *&nbs...
发布于 2022-03-03 11:42:00
PHP可以实现类似某些网站将用户名中间部分字符信息用 * 代替,还有某些网站将用户手机号或邮箱地址中间几位隐藏,以 * 代替,下面程序可以实现此功能,输出的结果为( )
<?php
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)
} else {
$rs = substr($str, 0, 3) . "***" . substr($str, -1)
}
}
return $rs
}
echo hideStar("513309965@qq.com")
?>
<?php
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)
} else {
$rs = substr($str, 0, 3) . "***" . substr($str, -1)
}
}
return $rs
}
echo hideStar("513309965@qq.com")
?>
登录后免费查看答案
关注者
0
被浏览
6