Php implements the method to replace the number * in the middle of the mobile phone number and hide the last digit of the IP address. The mobile phone number ip Address
This example describes how to replace the number * in the middle of the mobile phone number in php and how to hide the last digit of the IP address. We will share this with you for your reference. The details are as follows:
$string = "13826589549";$pattern = "/(\d{3})\d\d(\d{2})/";$replacement = "\$1****\$3";print preg_replace($pattern, $replacement, $string);
Output result: 138 **** 9549
The matching result is what I want, but the matching mode is incorrect. It can only match 7 digits, and the remaining 4 digits cannot match, and \ $3 does not exist at all.
Which of the following statements is true?
$string = "13826589549";$pattern = "/(\d{3})\d{4}(\d{4})/";$replacement = "\$1****\$2";print preg_replace($pattern, $replacement, $string);
You can also use the string truncation method to hide numbers in the middle.
function suohao($phone){ $p = substr($phone,0,3)."****".substr($phone,7,4); return $p;}echo suohao($string);
Output: 138 **** 9549
The last number of hidden IP addresses is *
<?php echo preg_replace("/[^\.]{1,3}$/","*",$ip); ?>
PS: here we will provide two very convenient Regular Expression tools for your reference:
JavaScript Regular Expression online testing tool:
Http://tools.jb51.net/regex/javascript
Regular Expression generation tool:
Http://tools.jb51.net/regex/create_reg