php 怎么把13412343312 替换成 134****3312

WBOY
Release: 2016-07-06 13:51:33
Original
874 people have browsed it

php 怎么把13412343312 替换成 134**3312

回复内容:

php 怎么把13412343312 替换成 134**3312

<code><?php echo substr_replace ('13412343312','****',3,4) ;
?></code>
Copy after login

说实话 我刚学PHP第一天。。。你的意思不就是取手机号的前3位后4位么

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

整理的常用的字符隐藏

<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>
Copy after login

<code>13412343312
134****3312
echo substr_replace('13412343312', '****', 3, 4);
3表示从第几个字符开始替换(位置从0开始算起).
4表示替换多少个字符.</code>
Copy after login

<code><?php echo substr_replace ('13412343312','*',3,7) ;
?></code>
Copy after login

一:substr_replace
二:preg_replace

分别查一下文档就好了

这不就是替换么?substr_replace

字符串替换。。。

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!