How to replace the mobile phone number in the document in php: 1. Replace by substr string interception method; 2. Replace the substring of the string by substr_replace.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How to replace the mobile phone number in the document with php?
php Several ways to replace mobile phone numbers with asterisks*
In php front-end development, we sometimes need to replace certain digits in a mobile phone number with asterisks Instead, this can protect the customer's basic information. The following are the two methods used. If necessary, you can take a look at
1.substr string interception method
$mobile = '18310000000'; $newMobile1 = substr($mobile, 0, 5).'****'.substr($mobile, 9); echo $newMobile1.'<br/>';
2.substr_replace replacement character Substring of string
$newMobile2 = substr_replace($mobile, '****',3, 4); echo $newMobile2.'<br/>';
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to replace the mobile phone number in the document in php. For more information, please follow other related articles on the PHP Chinese website!