The phone number associated tools commonly used functions of PHP

1, the phone number is correct or not is determined

// test phone number 
$ Phone = '17,777,777,777' ;
 $ pattern = '/ ^. 1 [356 789] \ {D}. 9 $ /' ;
 $ IS = the preg_match ( $ pattern , $ Phone );
 // output or 0. 1 
echo  IS $ ; // 1

2, four intermediate phone number is replaced ****

// test phone number 
$ Phone = '17,777,777,777' ;
 // 1, direct replacement 
echo  the substr_replace ( $ Phone , '****',. 3,. 4 );
 // Method 2, taken * + 
echo  substr ( $ Phone ., 0, 3) '****'. substr ( $ Phone ,. 7 );
 // method 3, n is replaced 
$ pattern = '/ (\ D {3}) \. 4 {D} (\. 4 {D }) / ' ;
 echo  preg_replace ( $ pattern ,' $ $ 2. 1 **** ', $ Phone );
 // results: 77777 177 ****

 

Guess you like

Origin www.cnblogs.com/deverz/p/11411270.html