Home > Backend Development > PHP Problem > How to hide mobile phone number in php

How to hide mobile phone number in php

coldplay.xixi
Release: 2023-03-06 11:04:01
Original
3747 people have browsed it

php隐藏手机号的方法:1、字符串截取法,代码为【$new_1=substr($tel, 0, 3).'****'.substr($tel, 7)】;2、替换字符串的子串,代码为【$new=substr_replace($tel,)】。

How to hide mobile phone number in php

php隐藏手机号的方法:

$num = "12345678910"

$str = substr_replace($num,'****',3,4);

How to hide mobile phone number in php

三种实现方式

<?php
$tel = &#39;12345678910&#39;;
//1.字符串截取法
$new_tel1 = substr($tel, 0, 3).&#39;****&#39;.substr($tel, 7);
var_dump($new_tel1);
//2.替换字符串的子串
$new_tel2 = substr_replace($tel, &#39;****&#39;, 3, 4);
var_dump($new_tel2);
//3.用正则
$new_tel3 = preg_replace(&#39;/(\d{3})\d{4}(\d{4})/&#39;, &#39;$1****$2&#39;, $tel);
var_dump($new_tel3);
?>
Copy after login

结果:

> string(11) "123****8910"
> string(11) "123****8910"
> string(11) "123****8910"
Copy after login

想了解更多编程学习,敬请关注php培训栏目!

The above is the detailed content of How to hide mobile phone number in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template