Home >php教程 >php手册 >PHP用***隐藏中间的数字或字母

PHP用***隐藏中间的数字或字母

WBOY
WBOYOriginal
2016-06-07 11:35:231756browse

该DEMO有隐藏手机号,邮箱和用户名三种方法。调用方法很简单,只要传要隐藏的字符串即可。
PHP用***隐藏中间的数字或字母function hideStar($str) { //用户名、邮箱、手机账号中间字符串以*隐藏 <br>     if (strpos($str, '@')) { <br>         $email_array = explode("@", $str); <br>         $prevfix = (strlen($email_array[0])          $count = 0; <br>         $str = preg_replace('/([\d\w+_-]{0,100})@/', '***@', $str, -1, $count); <br>         $rs = $prevfix . $str; <br>     } else { <br>         $pattern = '/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i'; <br>         if (preg_match($pattern, $str)) { <br>             $rs = preg_replace($pattern, '$1****$2', $str); // substr_replace($name,'****',3,4); <br>         } else { <br>             $rs = substr($str, 0, 3) . "***" . substr($str, -1); <br>         } <br>     } <br>     return $rs; <br> }隐藏字符串DEMO:http://www.sucaihuo.com/php/548.html

附件 PHP以星号隐藏用户名手机和邮箱.zip ( 2.02 KB 下载:8 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn