Rumah > pembangunan bahagian belakang > tutorial php > PHP 用户名、邮箱、手机账号中间字符串以隐藏

PHP 用户名、邮箱、手机账号中间字符串以隐藏

WBOY
Lepaskan: 2016-07-29 09:03:16
asal
1402 orang telah melayarinya
<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>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>}</span>
Salin selepas log masuk

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

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan