• 技术文章 >后端开发 >PHP问题

    php如何隐藏部分邮箱

    藏色散人藏色散人2020-09-30 09:56:08原创642

    php隐藏部分邮箱的方法:首先创建一个PHP示例文件;然后定义一个hideStr方法;接着通过“preg_replace('/([\d\w+_-]{0,100})@/', '***@', $str, -1, $count);”方法实现隐藏。

    推荐:《PHP视频教程

    PHP使用星号隐藏用户名,手机,邮箱的实现方法

    PHP使用星号替代用户名手机和邮箱这个在许多的活动界面会看到如淘宝的购物界面中的一些客户的支付宝号都是隐藏掉的哦,下面我们来看一下它的使用方法吧.

    <?php
     //用户名、邮箱、手机账号中间字符串以*隐藏
    function hideStr($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;
    }
    ?>
    <?php
    $account = "baidu.com";
    $email = "123456@qq.com";
    $phone = "15999888888";
    ?>

    以上就是php如何隐藏部分邮箱的详细内容,更多请关注php中文网其它相关文章!

    声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
    专题推荐:php
    上一篇:php如何使用post跳转页面 下一篇:php如何批量删除数据
    大前端线上培训班

    相关文章推荐

    • sae index.php隐藏的设置方法• nginx如何隐藏后缀名php• php如何实现超出隐藏• php如何隐藏实际文件下载地址

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网