该DEMO有隐藏手机号,邮箱和用户名三种方法。调用方法很简单,只要传要隐藏的字符串即可。function hideStar($str) { //用户名、邮箱、手机账号中间字符串以*隐藏 <br>
if (strpos($str, '@')) { <br>
$email_array = explode("@", $str); <br>
$prevfix = (strlen($email_array[0])
$count = 0; <br>
$str = preg_replace('/([\d\w+_-]{0,100})@/', '***@', $str, -1, $count); <br>
$rs = $prevfix . $str; <br>
} else { <br>
$pattern = '/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i'; <br>
if (preg_match($pattern, $str)) { <br>
$rs = preg_replace($pattern, '$1****$2', $str); // substr_replace($name,'****',3,4); <br>
} else { <br>
$rs = substr($str, 0, 3) . "***" . substr($str, -1); <br>
} <br>
} <br>
return $rs; <br>
}
隐藏字符串DEMO:http://www.sucaihuo.com/php/548.html
PHP以星号隐藏用户名手机和邮箱.zip ( 2.02 KB 下载:8 次 )
AD:真正免费,域名+虚机+企业邮箱=0元