Page 1 of 1

Censor last octet of an IP Address

Posted: Wed Feb 11, 2009 5:40 pm
by socket1
I am having trouble censoring the last octet of an IP address.

If I have the IP 168.251.436.255 I need it to end up like 168.251.436.*** or something similar.
I also need to have it do the same thing if I have an IP like 40.255.130.79 and I need it to end up like 40.255.130.***.

Re: Censor last octet of an IP Address

Posted: Wed Feb 11, 2009 5:59 pm
by bugrush

Code: Select all

$censored_ip = substr($ip, - strrpos($ip, '.')).'.***';

Re: Censor last octet of an IP Address

Posted: Wed Feb 11, 2009 6:01 pm
by socket1
Cool, thanks.

Re: Censor last octet of an IP Address

Posted: Thu Feb 12, 2009 6:01 am
by socket1
It reverses the IP in a weird way.
68.174.59.134 ----> 74.59.134.***

Re: Censor last octet of an IP Address

Posted: Thu Feb 12, 2009 6:18 am
by VladSun

Code: Select all

substr($ip, 0, strrpos($ip, '.')).'.***';

Re: Censor last octet of an IP Address

Posted: Sun Feb 15, 2009 8:53 am
by socket1
Thanks, it works now.