PHP使用星號(hào)替代用戶名手機(jī)和郵箱的實(shí)現(xiàn)代碼
PHP使用星號(hào)替代用戶名手機(jī)和郵箱這個(gè)在許多的活動(dòng)界面會(huì)看到如淘寶的購(gòu)物界面中的一些客戶的支付寶號(hào)都是隱藏掉的哦,下面我們來(lái)看一下它的使用方法吧.
<?php function hideStar($str) { //用戶名、郵箱、手機(jī)賬號(hào)中間字符串以*隱藏 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以星號(hào)隱藏用戶名手機(jī)和郵箱</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 rel="external nofollow" rel="external nofollow" >首 頁(yè)</a></li> <li><a href="http://www.phpfensi.com /templates" rel="external nofollow" >網(wǎng)站模板</a></li> <li><a href="http://www.phpfensi.com /js" rel="external nofollow" >網(wǎng)頁(yè)特效</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" >精選網(wǎng)址</a></li> </ul> <a class="logo" 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以星號(hào)隱藏用戶名手機(jī)和郵箱</a></h2> <table width="100%" class="table_parameters"> <tr class="tr_head"> <td>賬號(hào)</td> <td>郵箱</td> <td>手機(jī)</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>
總結(jié)
以上所述是小編給大家介紹的PHP使用星號(hào)替代用戶名手機(jī)和郵箱的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
laravel中短信發(fā)送驗(yàn)證碼的實(shí)現(xiàn)方法
在做用戶注冊(cè)和個(gè)人中心的安全管理時(shí)常常需要用到短信發(fā)送驗(yàn)證碼,下面這篇文章主要給大家介紹了關(guān)于laravel中短信發(fā)送驗(yàn)證碼的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-04-04Yii2框架實(shí)現(xiàn)登錄、退出及自動(dòng)登錄功能的方法詳解
這篇文章主要介紹了Yii2框架實(shí)現(xiàn)登錄、退出及自動(dòng)登錄功能的方法,結(jié)合實(shí)例形式詳細(xì)分析了Yii2框架實(shí)現(xiàn)登錄、退出及自動(dòng)登錄功能的原理、實(shí)現(xiàn)方法與相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2017-10-10Yii 框架應(yīng)用(Applications)操作實(shí)例詳解
這篇文章主要介紹了Yii 框架應(yīng)用(Applications)操作,結(jié)合實(shí)例形式詳細(xì)分析了Yii 框架應(yīng)用(Applications)基本配置、屬性、事件相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2020-05-05