This article describes how to hide the last two digits of an IP address in php as asterisks. it is a practical technique to use the regular expression matching method, for more information about how to hide IP addresses in php, see the example below. Share it with you for your reference. The specific implementation method is as follows:
In many public websites, the following IP segments are displayed as asterisks when the user's IP address is displayed. This protects user privacy, if you are interested, you can take a look.
Php regular format IP address, hide the last one.
Example
The code is as follows:
<? Php
// Hide the last digit
Return preg_replace ('/(\ d + )\. (\ d + )\. (\ d + )\. (\ d +)/is ', "$1. $2. $3. * ", $ ip );
// The last number of hidden IP addresses is *
Echo ereg_replace ("[^ \.] {1, 3} $", "*", $ ip );
?>
Example
How to hide the last or last segment of an IP address in php
The code is as follows:
<? Php
// -- Hide the last few IP addresses
$ Ip = '1970. 0.0.1 ';
$ Reg1 = '/((? : \ D + \.) {3}) \ d + /';
$ Reg2 = '~ (\ D +) \. (\ d + )~ ';
Echo preg_replace ($ reg1, "\ 1 *", $ ip); // The preceding output is 127.0.0 .*
Echo "------------------
";
Echo preg_replace ($ reg2, "$1. $2. *. *", $ ip); // The output result is 127. 0 .*.*
?>
Example
The code is as follows:
Function suohao ($ phone ){
$ P = substr ($ phone,). "*****". substr ($ phone );
Return $ p;
}
Of course, we can replace arrays 2 and 3 with arrays separated by commas (,) or combine arrays 0 and 1.
I hope this article will help you with php programming.