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自定义函数收代码
Aug 01 PHP
PHP自动选择 连接本地还是远程数据库
Dec 02 PHP
php连接数据库代码应用分析
May 29 PHP
解析isset与is_null的区别
Aug 09 PHP
新浪SAE云平台下使用codeigniter的数据库配置
Jun 12 PHP
VB中的RasEnumConnections函数返回632错误解决方法
Jul 29 PHP
php使用sql server验证连接数据库的方法
Dec 25 PHP
CentOS下搭建PHP环境与WordPress博客程序的全流程总结
May 07 PHP
PHP微信公众号自动发送红包API
Jun 01 PHP
PHP实现双链表删除与插入节点的方法示例
Nov 11 PHP
php实现分页功能的详细实例方法
Sep 29 PHP
php使用gearman进行任务分发操作实例详解
Feb 26 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 syntax error, unexpected $end 错误的一种原因及解决
2008/10/25 PHP
整理的一些实用WordPress后台MySQL操作命令
2013/01/07 PHP
如何使用PHP获取指定日期所在月的开始日期与结束日期
2013/08/01 PHP
php上传图片获取路径及给表单字段赋值的方法
2016/01/23 PHP
Mootools 1.2教程 输入过滤第二部分(字符串)
2009/09/15 Javascript
简短几句jquery代码的实现一个图片向上滚动切换
2011/09/02 Javascript
jQuery EasyUI API 中文文档 - DataGrid数据表格
2011/11/17 Javascript
js日期相关函数总结分享
2013/10/15 Javascript
display和visibility的区别示例介绍
2014/02/26 Javascript
实例讲解JS中数组Array的操作方法
2014/05/09 Javascript
node.js中的fs.createWriteStream方法使用说明
2014/12/17 Javascript
TypeError document.getElementById(...) is null错误原因
2015/05/18 Javascript
jQuery简单获取键盘事件的方法
2016/01/22 Javascript
在vue中通过axios异步使用echarts的方法
2018/01/13 Javascript
一步步教会你微信小程序的登录鉴权
2018/04/09 Javascript
Angular5中调用第三方库及jQuery的添加的方法
2018/06/07 jQuery
移动端滑动切换组件封装 vue-swiper-router实例详解
2018/11/25 Javascript
微信小程序wx.request的简单封装
2019/11/13 Javascript
[01:11:32]VG vs FNATIC 2019国际邀请赛小组赛 BO2 第二场 8.15
2019/08/17 DOTA
Python进程通信之匿名管道实例讲解
2015/04/11 Python
在Python中移动目录结构的方法
2016/01/31 Python
Python实现快速计算词频功能示例
2018/06/25 Python
python判断列表的连续数字范围并分块的方法
2018/11/16 Python
python实现淘宝秒杀脚本
2020/06/23 Python
浅析Python语言自带的数据结构有哪些
2019/08/27 Python
python程序中的线程操作 concurrent模块使用详解
2019/09/23 Python
在vscode中配置python环境过程解析
2019/09/28 Python
15行Python代码实现免费发送手机短信推送消息功能
2020/02/27 Python
Django mysqlclient安装和使用详解
2020/09/17 Python
Python+OpenCV检测灯光亮点的实现方法
2020/11/02 Python
Vans奥地利官方网站:美国原创极限运动潮牌
2018/09/30 全球购物
化学教学随笔感言
2014/02/19 职场文书
大学生求职信例文
2014/06/29 职场文书
公共艺术专业自荐信
2014/09/01 职场文书
那些美到让人窒息的诗句,值得你收藏!
2019/08/20 职场文书
python中sqllite插入numpy数组到数据库的实现方法
2021/06/21 Python