jiqing9006

三种实现方式

<?php
$tel = \'12345678910\';
//1.字符串截取法
$new_tel1 = substr($tel, 0, 3).\'****\'.substr($tel, 7);
var_dump($new_tel1);
//2.替换字符串的子串
$new_tel2 = substr_replace($tel, \'****\', 3, 4);
var_dump($new_tel2);
//3.用正则
$new_tel3 = preg_replace(\'/(\d{3})\d{4}(\d{4})/\', \'$1****$2\', $tel);
var_dump($new_tel3);
?>

结果:

> string(11) "123****8910"
> string(11) "123****8910"
> string(11) "123****8910"

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2021-11-27
  • 2021-11-27
  • 2021-12-11
  • 2021-11-27
猜你喜欢
  • 2021-06-04
  • 2021-11-27
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案