Home >Backend Development >PHP Problem >How to replace the mobile phone number in the document in php

How to replace the mobile phone number in the document in php

藏色散人
藏色散人Original
2021-07-23 09:09:141626browse

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.

How to replace the mobile phone number in the document in php

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.&#39;<br/>&#39;;

2.substr_replace replacement character Substring of string

$newMobile2 = substr_replace($mobile, &#39;****&#39;,3, 4);
echo $newMobile2.&#39;<br/>&#39;;

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn