Home > Backend Development > PHP Tutorial > 电话号码后几位替换成*该如何处理

电话号码后几位替换成*该如何处理

WBOY
Release: 2016-06-13 12:59:35
Original
942 people have browsed it

电话号码后几位替换成*
结果是类似于刘**这样的形式。
我的想法是前1位姓,直接截取出来,然后后几位名字直接替换成*,然后再重组一下,这样的思路应该没错吧?

但是用的函数好像不对,一直实现不出来,substr(),str_repalce().

应该用哪几个?
------解决方案--------------------

$s = '杨百万';<br />
<br />
//iconv 解决方案<br />
iconv_set_encoding("internal_encoding", "GBK");//是什么编码就填什么编码<br />
echo iconv_substr($s, 0, 1) . str_repeat('*', iconv_strlen($s)-1);<br />
<br />
//mb_string 解决方案<br />
mb_internal_encoding("gbk");//是什么编码就填什么编码<br />
echo mb_substr($s, 0, 1) . str_repeat('*', mb_strlen($s)-1);<br />
<br />
Copy after login

Related labels:
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