本篇內(nèi)容主要講解“PHP怎么用星號隱藏用戶名手機號碼和郵箱”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“PHP怎么用星號隱藏用戶名手機號碼和郵箱”吧!

一款簡單實用的PHP以星號隱藏用戶名手機號碼和郵箱實例,將用戶的一些文字信息隱藏一部分用星號代替,以便于保護用戶隱私。

隱藏函數(shù):
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;
}
測試數(shù)據(jù):
<?php $account = "sucaihuo.com"; $email = "123456789@qq.com"; $phone = "13800000000"; ?>
以星號*顯示實例:
<table width="100%"> <tr> <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> <td><?php echo hideStar($account);?></td> <td><?php echo hideStar($email);?></td> <td><?php echo hideStar($phone);?></td> </tr> </table>
到此,相信大家對“PHP怎么用星號隱藏用戶名手機號碼和郵箱”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
網(wǎng)頁標(biāo)題:PHP怎么用星號隱藏用戶名手機號碼和郵箱-創(chuàng)新互聯(lián)
轉(zhuǎn)載來源:http://chinadenli.net/article4/eosoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、微信小程序、Google、手機網(wǎng)站建設(shè)、面包屑導(dǎo)航、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容