Regular expression method 1. the string contains multiple mobile phone numbers. the code is as follows: & lt ;? Php $ s & amp; 39; manager Wang: 13999312365 manager Li: 13588958741 & amp; 39; $ spreg_replace (& amp; 39;
Regular expression method
1. the string contains multiple mobile phone numbers. the code is as follows:
-
- $ 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 manager Li: 135 ***** 741
- ?>
2. the string contains only one mobile phone number. the code is as follows:
-
- $ Haoma = "15012345678 ";
- Echo preg_replace ("/(d {3}) d {5}/", "$1 *****", $ haoma );
- // 150 ***** 678
- ?>
Implementation without regular expressions
1. use the substr_replace string to replace the function. the code is as follows:
-
- USD string1 = "13264309555 ";
- Echo substr_replace ($ string1 );
- // 132 ***** 555
- ?>
2. use the string truncation function substr. the code is as follows:
-
- Echo substr ($ string1,). "*****". substr ($ string1 );
- // 132 ***** 555
- ?>