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

藏色散人
Release: 2023-03-11 18:52:02
Original
1532 people have browsed it

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;;
Copy after login

2.substr_replace replacement character Substring of string

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

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!