php手机号中间几位替换星号实例
正则表达式方法
1、字符串中包含多个手机号码,代码如下:
<?php $s = '王经理:13999312365 李经理:13588958741' ; $s =preg_replace( '#(d{3})d{5}(d{3})#' , '${1}*****${2}' , $s ); echo $s ; //王经理:139*****365 李经理:135*****741 ?>2、字符串中只有一个手机号码,代码如下:
<?php $haoma = "15012345678" ; echo preg_replace( "/(d{3})d{5}/" , "$1*****" , $haoma ); //150*****678 ?>不用正则表达式实现
1、使用substr_replace字符串部分替换函数,代码如下:
<?php $string1 = "13264309555" ; echo substr_replace( $string1 , '*****' ,3,5); //132*****555 ?>2、使用字符串截取函数substr,代码如下:
<?php echo substr ( $string1 ,0,3). "*****" . substr ( $string1 ,8,3); //132*****555 ?>查看更多关于php手机号中间几位替换星号实例 - php函数的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did30616