欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP手機(jī)號(hào)中間四位用星號(hào)*代替顯示的實(shí)例

 更新時(shí)間:2017年06月02日 17:17:25   作者:alisleepy  
本篇文章主要介紹了PHP手機(jī)號(hào)中間四位用星號(hào)*代替顯示的實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

在顯示用戶(hù)列表的場(chǎng)景中,一般用到手機(jī)號(hào)的顯示時(shí)都需要對(duì)手機(jī)號(hào)進(jìn)行處理,一般是把中間的四位換成星號(hào)****,我本人用php處理的思路是進(jìn)行替換,用****替換手機(jī)號(hào)的中間四位

代碼如下:

$all_lottery_logs = ********;     //該語(yǔ)句是得到中獎(jiǎng)紀(jì)錄
//遍歷處理手機(jī)號(hào)
foreach($all_lottery_logs as $k=>$v){
   $xing = substr($v['tel'],3,4);  //獲取手機(jī)號(hào)中間四位
   $all_lottery_logs[$k]['tel'] = str_replace($xing,'****',$v['tel']);  //用****進(jìn)行替換
}

另外幾種方法

<?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);
?>

結(jié)果:

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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論