前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PHP字符中间加*星号代码,支持中英文

PHP字符中间加*星号代码,支持中英文

作者头像
硬核项目经理
发布2019-08-06 09:42:32
1.9K0
发布2019-08-06 09:42:32
举报

最近项目中遇到这个问题,自己写了一个,利用的是mb_相关的方法,比较简单方便

代码语言:javascript
复制
static function PassStart($str,$start,$end=0,$dot="*",$charset="UTF-8"){
$len = mb_strlen($str,$charset);
if($start==0||$start>$len){
$start = 1;
}
if($end!=0&&$end>$len){
$end = $len-2;
}
$endStart = $len-$end;
$top = mb_substr($str, 0,$start,$charset);
$bottom = "";
if($endStart>0){
$bottom =  mb_substr($str, $endStart,$end,$charset);
}
$len = $len-mb_strlen($top,$charset);
$len = $len-mb_strlen($bottom,$charset);
$newStr = $top;
for($i=0;$i<$len;$i++){
$newStr.=$dot;
}
$newStr.=$bottom;
return $newStr;
}

直接调用即可PassStart("", 4,4);

输出结果:

"cardid":"6222***********3655","certifId":"4304**********1011","mobile":"138****6306","name":"张*",

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2016-11-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 码农老张 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档