Page 1 of 1

Display reverse subnet mask

Posted: Tue Oct 13, 2009 8:56 pm
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!

Re: Display reverse subnet mask

Posted: Tue Oct 13, 2009 9:45 pm
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;

Re: Display reverse subnet mask

Posted: Tue Oct 13, 2009 9:52 pm
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.