隐藏函数:
1 function hideStar($str) { //用户名、邮箱、手机账号中间字符串以*隐藏 2 if (strpos($str, \'@\')) { 3 $email_array = explode("@", $str); 4 $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($str, 0, 3); //邮箱前缀 5 $count = 0; 6 $str = preg_replace(\'/([\d\w+_-]{0,100})@/\', \'***@\', $str, -1, $count); 7 $rs = $prevfix . $str; 8 } else { 9 $pattern = \'/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i\'; 10 if (preg_match($pattern, $str)) { 11 $rs = preg_replace($pattern, \'$1****$2\', $str); // substr_replace($name,\'****\',3,4); 12 } else { 13 $rs = substr($str, 0, 3) . "***" . substr($str, -1); 14 } 15 } 16 return $rs; 17 }