Regular Expression method
1, the string contains more than one mobile phone number
| The code is as follows |
Copy Code |
|
<?php
$s = ' manager Wang: 13999312365 manager li: 13588958741 ';
$s =preg_replace (' # (D{3}) d{5} (D{3}) # ', ' ${1}*****${2} ', $s);
Echo $s;
Manager Wang: 139*****365 li: 135*****741
?> |
2, only one cell phone number in the string
| The code is as follows |
Copy Code |
|
<?php
$haoma = "15012345678";
echo Preg_replace ("/(D{3}) d{5}/", "$1*****", $haoma);
150*****678
?> |
Do not implement the regular expression
1, use Substr_replace string partial substitution function
| The code is as follows |
Copy Code |
|
<?php
$string 1 = "13264309555";
Echo Substr_replace ($string 1, ' * * * *, 3,5);
132*****555
?> |
2. Use string intercept function substr
| code is as follows |
copy code |
|
<?php
Echo substr ($string 1,0,3). ". substr ($string 1,8,3);
//132*****555
|