首页 > 移动平台 > 详细

php进行过滤用户名、邮箱、手机账号中间字符串以*隐藏

时间:2020-02-03 18:32:14      阅读:131      评论:0      收藏:0      [点我收藏+]

  php进行过滤用户名、邮箱、手机账号中间字符串以*隐藏

 

 在自定义函数文件中加入(网站根目录api/extend.func.php)

//用户名、邮箱、手机账号中间字符串以*隐藏 
function xhdestar($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; 
}

  实例用法:chip/contact.htm中调用

{xhdestar($member[mobile])}

  

php进行过滤用户名、邮箱、手机账号中间字符串以*隐藏

原文:https://www.cnblogs.com/68xi/p/12256403.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!