PHP使用星號(hào)隱藏用戶名,手機(jī)和郵箱的實(shí)現(xiàn)方法
本文實(shí)例講述了PHP使用星號(hào)隱藏用戶名,手機(jī)和郵箱的實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
PHP使用星號(hào)替代用戶名手機(jī)和郵箱這個(gè)在許多的活動(dòng)界面會(huì)看到如淘寶的購物界面中的一些客戶的支付寶號(hào)都是隱藏掉的哦,下面我們來看一下它的使用方法吧.
<?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 = "jb51.net"; $email = "123456789@qq.com"; $phone = "13888888888"; ?> <!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="css/common.css" /> <style type="text/css"> </style> </head> <body> <div class="head"> <div class="head_inner clearfix"> <ul id="nav"> <li><a href="/">首 頁</a></li> <li><a href="/templates">網(wǎng)站模板</a></li> <li><a href="/js">網(wǎng)頁特效</a></li> <li><a href="/php">PHP</a></li> <li><a href="/site">精選網(wǎng)址</a></li> </ul> <a class="logo" href=""><img src="images/logo.jpg" alt="素材火logo" /></a> </div> </div> <div class="container"> <div class="demo"> <h2 class="title"><a href="#">教程: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>
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php字符串(string)用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語法入門教程》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
IIS下PHP連接數(shù)據(jù)庫提示mysql undefined function mysql_connect()
在很多php教程初學(xué)者都會(huì)在初次php mysql時(shí)出來undefined function mysql_connect() 錯(cuò)誤提示,下面我們來分析原因中。2010-06-06解析curl提交GET,POST,Cookie的簡(jiǎn)單方法
本篇文章是對(duì)curl提交GET,POST,Cookie的簡(jiǎn)單方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06php使用PhpSpreadsheet導(dǎo)出Excel表格的實(shí)例詳解
這篇文章將給大家介紹php使用PhpSpreadsheet導(dǎo)出Excel表格的實(shí)例,文中通過代碼示例給大家講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-01-01php中通過正則表達(dá)式下載內(nèi)容中的遠(yuǎn)程圖片的函數(shù)代碼
下午抽空寫了個(gè)用PHP正則表達(dá)式判斷內(nèi)容中的圖片,下載并保存非本域名下的圖片的程序2012-01-01PHP實(shí)現(xiàn)的簡(jiǎn)單適配器模式示例
這篇文章主要介紹了PHP實(shí)現(xiàn)的簡(jiǎn)單適配器模式,結(jié)合具體實(shí)例形式分析了php適配器模式的實(shí)現(xiàn)技巧與調(diào)用方法,需要的朋友可以參考下2017-06-06Windows下PHP開發(fā)環(huán)境搭建教程(Apache+PHP+MySQL)
這篇文章主要為大家詳細(xì)介紹了Windows下PHP開發(fā)環(huán)境搭建教程:Apache+PHP+MySQL,具有一定的實(shí)用性和參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06PHP實(shí)現(xiàn)隨機(jī)發(fā)撲克牌
這篇文章主要為大家詳細(xì)介紹了PHP實(shí)現(xiàn)隨機(jī)發(fā)撲克牌,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04php數(shù)組函數(shù)序列之in_array() - 查找數(shù)組中是否存在指定值
in_array()定義和用法 in_array() 函數(shù)查找數(shù)組中是否存在指定值2011-11-11