扣丁学堂PHP培训简述如何用星号替代用户名手机和邮箱

2018-07-23 14:12:58 399浏览

今天扣丁学堂PHP培训小编给广大的小伙伴们分享一下如何用星号替代用户名手机和邮箱,文章中会有代码列出,对PHP感兴趣的小伙伴下面就随小编来看一下PHP使用星号替代用户名手机和邮箱的实现代码吧。

扣丁学堂PHP培训简述如何用星号替代用户名手机和邮箱


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开发方面问题的小伙伴可以登录扣丁学堂官网咨询。扣丁学堂不仅有专业的PHP培训班供大家报名学习,还有大量专业的老师全程授课,和紧随时代发展不断更新的课程体系,定能让你学有所成。扣丁学堂PHP技术交流群:374332265。




扣丁学堂微信公众号

【关注微信公众号获取更多学习资料】

 


查看更多关于“php培训资讯”的相关文章>>



标签: 扣丁学堂PHP培训 如何用星号替代用户名手机和邮箱 PHP在线学习 PHP培训 PHP在线视频 PHP基础学习 PHP基础视频 PHP入门视频

热门专区

暂无热门资讯

课程推荐

微信
微博
15311698296

全国免费咨询热线

邮箱:codingke@1000phone.com

官方群:148715490

北京千锋互联科技有限公司版权所有   北京市海淀区宝盛北里西区28号中关村智诚科创大厦4层
京ICP备12003911号-6   Copyright © 2013 - 2019

京公网安备 11010802030908号