PHP手机号中间四位用星号*代替显示的实例
2024-11-25 09:32:05
<?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); ?>