PHP怎么用星号隐藏用户名手机号码和邮箱
本篇内容主要讲解“PHP怎么用星号隐藏用户名手机号码和邮箱”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“PHP怎么用星号隐藏用户名手机号码和邮箱”吧!
一款简单实用的PHP以星号隐藏用户名手机号码和邮箱实例,将用户的一些文字信息隐藏一部分用星号代替,以便于保护用户隐私。
隐藏函数:
functionhideStar($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;}
测试数据:
<?php$account="sucaihuo.com";$email="123456789@qq.com";$phone="13800000000";?>
以星号*显示实例:
<tablewidth="100%"><tr><td>账号</td><td>邮箱</td><td>手机</td></tr><tr><td><?phpecho$account;?></td><td><?phpecho$email;?></td><td><?phpecho$phone;?></td></tr><tr><td><?phpechohideStar($account);?></td><td><?phpechohideStar($email);?></td><td><?phpechohideStar($phone);?></td></tr></table>
到此,相信大家对“PHP怎么用星号隐藏用户名手机号码和邮箱”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。