Home Backend Development PHP Tutorial PHP realizes hiding username mobile phone and email address into asterisk code sharing

PHP realizes hiding username mobile phone and email address into asterisk code sharing

Feb 09, 2018 am 09:28 AM
php cell phone Mail

PHP使用星号替代用户名手机和邮箱这个在许多的活动界面会看到如淘宝的购物界面中的一些客户的支付宝号都是隐藏掉的哦,下面我们来看一下它的使用方法吧.本文主要和大家介绍了PHP使用星号替代用户名手机和邮箱的实现代码,需要的朋友可以参考下,希望能帮助到大家。


<?php 
function hideStar($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 = "phpfensi.com"; 
$email = "416148489@qq.com"; 
$phone = "18005152525"; 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>演示:PHP以星号隐藏用户名手机和邮箱</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/> 
    <link rel="stylesheet" type="text/css" href="http://www.phpfensi.com /jquery/css/common.css" rel="external nofollow" /> 
    <style type="text/css"> 
    </style> 
  </head> 
  <body> 
    <p class="head"> 
      <p class="head_inner clearfix"> 
        <ul id="nav"> 
          <li><a href="http://www.phpfensi.com " rel="external nofollow" rel="external nofollow" >首 页</a></li> 
          <li><a href="http://www.phpfensi.com /templates" rel="external nofollow" >网站模板</a></li> 
          <li><a href="http://www.phpfensi.com /js" rel="external nofollow" >网页特效</a></li> 
          <li><a href="http://www.phpfensi.com /php" rel="external nofollow" >PHP</a></li> 
          <li><a href="http://www.phpfensi.com /site" rel="external nofollow" >精选网址</a></li> 
        </ul> 
        <a class="logo" href="http://www.phpfensi.com " rel="external nofollow" rel="external nofollow" ><img src="http://www.phpfensi.com /Public/images/logo.jpg" alt="素材火logo" /></a> 
      </p> 
    </p> 
    <p class="container"> 
      <p class="demo"> 
        <h2 class="title"><a href="http://www.phpfensi.com /js/548.html" rel="external nofollow" >教程:PHP以星号隐藏用户名手机和邮箱</a></h2> 
        <table width="100%" class="table_parameters"> 
          <tr class="tr_head"> 
            <td>账号</td> 
            <td>邮箱</td> 
            <td>手机</td> 
          </tr> 
          <tr> 
            <td><?php echo $account; ?></td> 
            <td><?php echo $email; ?></td> 
            <td><?php echo $phone; ?></td> 
          </tr> 
          <tr class="red"> 
            <td><?php echo hideStar($account); ?></td> 
            <td><?php echo hideStar($email); ?></td> 
            <td><?php echo hideStar($phone); ?></td> 
          </tr> 
        </table> 
      </p> 
    </p> 
  </body> 
</html>
Copy after login

相关推荐:

使用CSS 给表单必选项添加星号实例分享

php正则表达式实现手机号码中间4位用星号替换显示功能

PHP怎样实现用星号*代替显示手机号教程详解

The above is the detailed content of PHP realizes hiding username mobile phone and email address into asterisk code sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

How to simplify email marketing with Composer: DUWA.io's application practices How to simplify email marketing with Composer: DUWA.io's application practices Apr 18, 2025 am 11:27 AM

I'm having a tricky problem when doing a mail marketing campaign: how to efficiently create and send mail in HTML format. The traditional approach is to write code manually and send emails using an SMTP server, but this is not only time consuming, but also error-prone. After trying multiple solutions, I discovered DUWA.io, a simple and easy-to-use RESTAPI that helps me create and send HTML mail quickly. To further simplify the development process, I decided to use Composer to install and manage DUWA.io's PHP library - captaindoe/duwa.

The Continued Use of PHP: Reasons for Its Endurance The Continued Use of PHP: Reasons for Its Endurance Apr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

bitget new user registration guide 2025 bitget new user registration guide 2025 Apr 21, 2025 pm 10:09 PM

The steps to register for Bitget in 2025 include: 1. Prepare a valid email or mobile phone number and a stable network; 2. Visit the Bitget official website; 3. Enter the registration page; 4. Select the registration method; 5. Fill in the registration information; 6. Agree to the user agreement; 7. Complete verification; 8. Obtain and fill in the verification code; 9. Complete registration. After registering, it is recommended to log in to the account, perform KYC identity verification, and set up security measures to ensure the security of the account.

Using Laravel: Streamlining Web Development with PHP Using Laravel: Streamlining Web Development with PHP Apr 19, 2025 am 12:18 AM

Laravel optimizes the web development process including: 1. Use the routing system to manage the URL structure; 2. Use the Blade template engine to simplify view development; 3. Handle time-consuming tasks through queues; 4. Use EloquentORM to simplify database operations; 5. Follow best practices to improve code quality and maintainability.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

See all articles