PHP使用星号替代用户名手机与邮箱部分字符

php中世界最好的语言
发布: 2018-05-19 10:07:00
原创
1942人浏览过

这次给大家带来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> 
    <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" >@@##@@</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>
登录后复制

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

php处理抢购类高并发请求实现详解

redis计数器类使用步骤详解

PHP使用星号替代用户名手机与邮箱部分字符

以上就是PHP使用星号替代用户名手机与邮箱部分字符的详细内容,更多请关注php中文网其它相关文章!

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号