Php regular format IP address, hide the last one.
Example
The code is as follows: |
Copy code |
<? 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: |
Copy code |
<? // -- 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 "------------------ <br/> "; Echo preg_replace ($ reg2, "$1. $2. *. *", $ ip); // The output result is 127. 0 .*.* ?> |
Example
The code is as follows: |
Copy code |
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.