Show part of IP address

85.124.99.2

How to hide the last two numbers from IP?

and do this:

86.124.xxx.xxx

+4
source share
4 answers

Posted it fast

 $ip = "85.124.99.2"; $parts = explode('.',$ip); $new_ip = $parts[0].'.'.$parts[1].'.xxx.xxx'; 

Caution: you must check the length of parts before accessing $ parts [n]

+11
source
 $ip = preg_replace('/\.\d+\.\d+$/', '.xxx.xxx', $ip); 
+2
source

Use the IP address and print only what you want. Not sure, other than what you mean by "do it," other than printing on the screen.

0
source

Use this regex.

 (?!\d{1,3}\.\d{1,3}\.)\d 

Example

 137.133.204.130 -> 137.133.***.*** 93.108.72.157 -> 93.108.**.*** 
0
source

All Articles