PHP使用星号替代用户名手机和邮箱的实现代码


Posted in PHP onFebruary 07, 2018

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

<?php 
function hideStar($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 = "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> 
    <div class="head"> 
      <div 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> 
      </div> 
    </div> 
    <div class="container"> 
      <div 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> 
      </div> 
    </div> 
  </body> 
</html>

总结

以上所述是小编给大家介绍的PHP使用星号替代用户名手机和邮箱的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

PHP 相关文章推荐
PHP可逆加密/解密函数分享
Sep 25 PHP
解析php中const与define的应用区别
Jun 18 PHP
php cURL和Rolling cURL并发方式比较
Oct 30 PHP
排序算法之PHP版快速排序、冒泡排序
Apr 09 PHP
PHP调用.NET的WebService 简单实例
Mar 27 PHP
详解PHP+AJAX无刷新分页实现方法
Nov 03 PHP
实例讲解yii2.0在php命令行中运行的步骤
Dec 01 PHP
ThinkPHP 模板substr的截取字符串函数详解
Jan 09 PHP
实例讲解PHP页面静态化
Feb 05 PHP
thinkphp集成前端脚手架Vue-cli的教程图解
Aug 30 PHP
thinkphp5实现微信扫码支付
Dec 23 PHP
PHP 技巧 * SVG 保存为图片(分享图生成)
Apr 02 PHP
PHP unlink与rmdir删除目录及目录下所有文件实例代码
Feb 07 #PHP
php删除一个路径下的所有文件夹和文件的方法
Feb 07 #PHP
浅析PHP类的反射来实现依赖注入过程
Feb 06 #PHP
php打开本地exe程序,js打开本地exe应用程序,并传递相关参数方法
Feb 06 #PHP
PHP给源代码加密的几种方法汇总(推荐)
Feb 06 #PHP
php 替换文章中的图片路径,下载图片到本地服务器的方法
Feb 06 #PHP
PHP定义字符串的四种方式详解
Feb 06 #PHP
You might like
社区(php&amp;&amp;mysql)四
2006/10/09 PHP
优化使用mysql存储session的php代码
2008/01/10 PHP
PHP的全局错误处理详解
2016/04/25 PHP
Extjs学习笔记之三 extjs form更多的表单项
2010/01/07 Javascript
jquery插件 cluetip 关键词注释
2010/01/12 Javascript
JavaScript中for循环的使用详解
2015/06/03 Javascript
举例详解AngularJS中ngShow和ngHide的使用方法
2015/06/19 Javascript
基于JQuery及AJAX实现名人名言随机生成器
2017/02/10 Javascript
从零开始学习Node.js系列教程五:服务器监听方法示例
2017/04/13 Javascript
基于Vue2的独立构建与运行时构建的差别(详解)
2017/12/06 Javascript
vue中多路由表头吸顶实现的几种布局方式
2019/04/12 Javascript
详解微信小程序实现跑马灯效果(附完整代码)
2019/04/29 Javascript
JS实现扫码枪扫描二维码功能
2020/01/03 Javascript
详解Vue的异步更新实现原理
2020/12/22 Vue.js
Python微信库:itchat的用法详解
2017/08/14 Python
使用Python实现windows下的抓包与解析
2018/01/15 Python
解决Python网页爬虫之中文乱码问题
2018/05/11 Python
详解django中url路由配置及渲染方式
2019/02/25 Python
解决pycharm中opencv-python导入cv2后无法自动补全的问题(不用作任何文件上的修改)
2020/03/05 Python
python网络编程:socketserver的基本使用方法实例分析
2020/04/09 Python
Python xmltodict模块安装及代码实例
2020/10/05 Python
css3实现一个div设置多张背景图片及background-image属性实例演示
2017/08/10 HTML / CSS
html5 canvas实现跟随鼠标旋转的箭头
2016/03/11 HTML / CSS
详解Html5 Canvas画线有毛边解决方法
2018/03/01 HTML / CSS
HTML5新增加标签和功能概述
2016/09/05 HTML / CSS
HTML5拖放API实现拖放排序的实例代码
2017/05/11 HTML / CSS
中邮全球便购:中国邮政速递物流
2017/03/04 全球购物
英国DIY汽车维修配件网站:DIY Car Service Parts
2019/08/30 全球购物
数学专业毕业生自荐信
2013/11/10 职场文书
跟单文员岗位职责
2014/01/03 职场文书
《春雨》教学反思
2014/04/24 职场文书
2014年教务工作总结
2014/12/03 职场文书
2015年民主生活会发言材料
2014/12/15 职场文书
2016年教师政治思想表现评语
2015/12/02 职场文书
在CSS中映射鼠标位置并实现通过鼠标移动控制页面元素效果(实例代码)
2021/04/22 HTML / CSS
苹果macOS 13开发者预览版Beta 8发布 正式版10月发布
2022/09/23 数码科技