How to replace 13412343312 with 134**3312
in phpHow to replace 13412343312 with 134**3312
in php
<code><?php echo substr_replace ('13412343312','****',3,4) ; ?></code>
To be honest, I just learned PHP on the first day. . . Don’t you mean to get the first 3 digits and last 4 digits of the mobile phone number?
substr_replace('13412343312 ','**',3,6);
Hide commonly used characters in order
<code>//字段文字内容隐藏处理方法 function hidecard($cardnum,$type=1,$default=""){ if(empty($cardnum)) { return $default; } if($type==1){ $cardnum = substr($cardnum,0,3).str_repeat("*",12).substr($cardnum,strlen($cardnum)-4);//身份证 }elseif($type==2){ $cardnum = substr($cardnum,0,3).str_repeat("*",5).substr($cardnum,strlen($cardnum)-4);//手机号 }elseif($type==3){ $cardnum = str_repeat("*",strlen($cardnum)-4).substr($cardnum,strlen($cardnum)-4);//银行卡 }elseif($type==4){ $cardnum = substr($cardnum,0,3).str_repeat("*",strlen($cardnum)-3);//用户名 }elseif($type==5){ $cardnum = substr($cardnum,0,3).str_repeat("*",3).substr($cardnum,strlen($cardnum)-3);//新用户名 } return $cardnum; }</code>
<code>13412343312 134****3312 echo substr_replace('13412343312', '****', 3, 4); 3表示从第几个字符开始替换(位置从0开始算起). 4表示替换多少个字符.</code>
<code><?php echo substr_replace ('13412343312','*',3,7) ; ?></code>
One:substr_replace
Two:preg_replace
Just check the documentation separately
Isn’t this just a replacement? substr_replace
String replacement. . .