Today, small part of the students to introduce the use of preg_replace function to the middle of a number of mobile phone numbers to replace the Chengshing number, this in many sites will have to do so, let me introduce the example method.
Regular Expression methods
1, the string contains more than one mobile phone number
| The code is as follows |
Copy Code |
$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 mobile phone number in the string
| The code is as follows |
Copy Code |
$haoma = "15012345678"; echo Preg_replace ("/(D{3}) d{5}/", "$1*****", $haoma); 150*****678 ?> |
Do not implement regular expressions
1. Replace the function with the Substr_replace string part
| The code is as follows |
Copy Code |
$string 1 = "13264309555"; Echo Substr_replace ($string 1, ' * * * * *, 3,5); 132*****555 ?> |
2. Using the string intercept function substr
| The code is as follows |
Copy Code |
Echo substr ($string 1,0,3). " ". substr ($string 1,8,3); 132*****555 ?> |
http://www.bkjia.com/PHPjc/632653.html www.bkjia.com true http://www.bkjia.com/PHPjc/632653.html techarticle Today, small part of the students to introduce the use of preg_replace function to the middle of a number of mobile phone numbers to replace the Chengshing number, this in many sites will have to do, the following I would like to introduce the instance of the party ...