php方法 隱藏手機號中間四位


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

 

三種實現方式

<?php
$tel = '12345678910';
//1.字符串截取法
$new_tel1 = substr($tel, 0, 3).'****'.substr($tel, 7);
var_dump($new_tel1);
//2.替換字符串的子串
$new_tel2 = substr_replace($tel, '****', 3, 4);
var_dump($new_tel2);
//3.用正則
$new_tel3 = preg_replace('/(\d{3})\d{4}(\d{4})/', '$1****$2', $tel);
var_dump($new_tel3);
?>
結果:

> string(11) "123****8910"
> string(11) "123****8910"
> string(11) "123****8910"

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM