PHP How to replace 13412343312 into 134****3312

Source: Internet
Author: User
PHP How to replace 13412343312 to 134 **3312

Reply content:

PHP How to replace 13412343312 into 134**3312


  
   

To be honest, I just learned the first day of PHP ... Do you mean to take the first 3 digits of the cell phone number and then 4?

Substr_replace (' 13412343312 ', ' * * ', 3,6);

Organize the usual characters to hide

//字段文字内容隐藏处理方法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;}

13412343312134****3312echo substr_replace('13412343312', '****', 3, 4);3表示从第几个字符开始替换(位置从0开始算起).4表示替换多少个字符.


  
   

One:substr_replace
Two:preg_replace

Just check the documentation, please.

Isn't that just a replacement? Substr_replace

String substitution ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.