Reputation: 43
85.124.99.2
How can I hide the last two numbers from the IP?
and make it like:
86.124.xxx.xxx
Upvotes: 4
Views: 945
Reputation: 13126
Wrote this quickly
$ip = "85.124.99.2";
$parts = explode('.',$ip);
$new_ip = $parts[0].'.'.$parts[1].'.xxx.xxx';
Warning: You should test the length of parts before accessing $parts[n]
Upvotes: 11
Reputation: 46425
Use this regex.
(?!\d{1,3}\.\d{1,3}\.)\d
Sample
137.133.204.130 -> 137.133.***.***
93.108.72.157 -> 93.108.**.***
Upvotes: 0
Reputation: 19755
Consume the IP Address and only print out what you want. Not sure other than that what you mean by "make it" other than printing on the screen.
Upvotes: 0