Display reverse subnet mask

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
yintong
Forum Newbie
Posts: 5
Joined: Tue Oct 13, 2009 8:52 pm

Display reverse subnet mask

Post by yintong »

Hi, how do i actually reverse the subnet mask and write it into a TextFile?

Example: A user enter 255.255.255.0 in a TextBox. But when written into a TextFile, it is being reversed to 0.0.0.255

Thanks in advance!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Display reverse subnet mask

Post by requinix »

I'm thinking ip2long, the ~ operator, and long2ip should do the trick.

Code: Select all

$ip = "255.255.255.0";
$reversed = long2ip(~ip2long($ip));
 
echo $reversed;
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Display reverse subnet mask

Post by Weiry »

Definitely a better approach than i posted in the other exact same thread.
Ive gone and noted that down for future use too :)
cheers tasairis.
Post Reply