search
HomeBackend DevelopmentPHP ProblemHow to hide part of the mailbox with php regular expression

php正则隐藏部分邮箱的方法:首先创建一个PHP示例文件;然后通过正则表达式“preg_replace('/([\d\w+_-]{0,100})@/', '***@', $str, -1, $count);”隐藏部分邮箱即可。

How to hide part of the mailbox with php regular expression

本文操作环境:Windows7系统、PHP7.1版,DELL G3电脑

php正则怎么隐藏部分邮箱?

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

<?php
 //用户名、邮箱、手机账号中间字符串以*隐藏
function hideStr($str) {
  if (strpos($str, &#39;@&#39;)) {
    $email_array = explode("@", $str);
    //邮箱前缀
    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($str, 0, 3); 
    $count = 0;
    $str = preg_replace(&#39;/([\d\w+_-]{0,100})@/&#39;, &#39;***@&#39;, $str, -1, $count);
    $rs = $prevfix . $str;
  } else {
    //正则手机号
    $pattern = &#39;/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i&#39;;
    if (preg_match($pattern, $str)) {
      $rs = preg_replace($pattern, &#39;$1****$2&#39;, $str); // substr_replace($name,&#39;****&#39;,3,4);
    } else {
      $rs = substr($str, 0, 3) . "***" . substr($str, -1);
    }
  }
  return $rs;
}
?>
<?php
$account = "baidu.com";
$email = "123456@qq.com";
$phone = "15999888888";
?>

推荐学习:《PHP视频教程

The above is the detailed content of How to hide part of the mailbox with php regular expression. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Atom editor mac version download

Atom editor mac version download

The most popular open source editor