Censor last octet of an IP Address

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Censor last octet of an IP Address

Post 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.***.
bugrush
Forum Newbie
Posts: 15
Joined: Tue Dec 16, 2008 3:00 pm

Re: Censor last octet of an IP Address

Post by bugrush »

Code: Select all

$censored_ip = substr($ip, - strrpos($ip, '.')).'.***';
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Re: Censor last octet of an IP Address

Post by socket1 »

Cool, thanks.
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Re: Censor last octet of an IP Address

Post by socket1 »

It reverses the IP in a weird way.
68.174.59.134 ----> 74.59.134.***
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Censor last octet of an IP Address

Post by VladSun »

Code: Select all

substr($ip, 0, strrpos($ip, '.')).'.***';
There are 10 types of people in this world, those who understand binary and those who don't
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Re: Censor last octet of an IP Address

Post by socket1 »

Thanks, it works now.
Post Reply