PHP头条
热点:

php字符串替换为星号或其它字符(手机号,身份证)


在php中字符串中指定位置的字符替换为星号我们有很我函数可以实现如有substr,preg_replace,substr_replace等下面我分别给这三个函数分别介绍一个实例,主要讲到电话,身份证.

手机号码字符串替换为星号代码:

或用正则

替换字符串中间位置字符为星号

function half_replace($str){  
    $len = strlen($str)/2;  
    return substr_replace($str,str_repeat('*',$len),ceil(($len)/2),$len);  
}  
echo half_replace('test'),"n",half_replace('tests'),"n",half_replace('exceptions');

PHP身份证号打星号

echo strlen($idcard)==15?substr_replace($idcard,"****",8,4):(strlen($idcard)==18?substr_replace($idcard,"****",10,4):"phprm.com提示身份证位数不正常!");


文章地址:

转载随意^^请带上本文地址!

www.phpzy.comtrue/phpyy/4941.htmlTechArticlephp字符串替换为星号或其它字符(手机号,身份证) 在php中字符串中指定位置的字符替换为星号我们有很我函数可以实现如有substr,preg_replace,substr_replace等下面我分别给这三个函数分别...

相关文章

相关频道:

PHP之友评论

今天推荐