首頁 > 後端開發 > php教程 > PHP 使用者名稱、信箱、手機帳號中間字串以隱藏

PHP 使用者名稱、信箱、手機帳號中間字串以隱藏

WBOY
發布: 2016-07-29 09:03:16
原創
1402 人瀏覽過
<span>function </span><span>hideStar</span>(<span>$str</span>) { <span>//</span><span>用户名、邮箱、手机账号中间字符串以</span><span>*</span><span>隐藏
</span><span>if </span>(<span>strpos</span>(<span>$str</span><span>, </span><span>'@'</span>)) {
      <span>$email_array </span><span>= </span><span>explode</span>(<span>"@"</span><span>, </span><span>$str</span>)<span>;
</span><span>$prevfix </span><span>= </span>(<span>strlen</span>(<span>$email_array</span><span>[</span><span>0</span><span>]</span>) <span>< </span><span>4</span>) <span>? </span><span>"" </span><span>: </span><span>substr</span>(<span>$str</span><span>, </span><span>0</span><span>, </span><span>3</span>)<span>; </span><span>//</span><span>邮箱前缀
</span><span>$count </span><span>= </span><span>0</span><span>;
</span><span>$str </span><span>= </span><span>preg_replace</span>(<span>'/([\d\w+_-]{0,100})@/'</span><span>, </span><span>'***@'</span><span>, </span><span>$str</span><span>, </span><span>-</span><span>1</span><span>, </span><span>$count</span>)<span>;
</span><span>$rs </span><span>= </span><span>$prevfix </span><span>. </span><span>$str</span><span>;
</span>} <span>else </span>{
      <span>$pattern </span><span>= </span><span>'/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i'</span><span>;
</span><span>if </span>(<span>preg_match</span>(<span>$pattern</span><span>, </span><span>$str</span>)) {
         <span>$rs </span><span>= </span><span>preg_replace</span>(<span>$pattern</span><span>, </span><span>'$1****$2'</span><span>, </span><span>$str</span>)<span>; </span><span>// substr_replace($name,'****',3,4);
</span>} <span>else </span>{
         <span>$rs </span><span>= </span><span>substr</span>(<span>$str</span><span>, </span><span>0</span><span>, </span><span>3</span>) <span>. </span><span>"***" </span><span>. </span><span>substr</span>(<span>$str</span><span>, </span><span>-</span><span>1</span>)<span>;
</span>}
   }
   <span>return </span><span>$rs</span><span>;
</span>}
登入後複製

以上就介绍了PHP 用户名、邮箱、手机账号中间字符串以隐藏,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板