note 94787 added to function.ip2long

From: Date: Wed, 25 Nov 2009 01:45:31 +0000
Subject: note 94787 added to function.ip2long
Groups: php.notes 
Request: Send a blank email to php-notes+get-163257@lists.php.net to get a copy of this message
A quick method to convert a netmask (ex: 255.255.255.240) to a cidr mask (ex: /28): <?php function mask2cidr($mask){ $long = ip2long($mask); $base = ip2long('255.255.255.255'); return 32-log(($long ^ $base)+1,2); /* xor-ing will give you the inverse mask, log base 2 of that +1 will return the number of bits that are off in the mask and subtracting from 32 gets you the cidr notation */ } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 69.141.7.111 ---- Manual Page -- http://www.php.net/manual/en/function.ip2long.php Edit -- https://master.php.net/note/edit/94787 Del: integrated -- https://master.php.net/note/delete/94787/integrated Del: useless -- https://master.php.net/note/delete/94787/useless Del: bad code -- https://master.php.net/note/delete/94787/bad+code Del: spam -- https://master.php.net/note/delete/94787/spam Del: non-english -- https://master.php.net/note/delete/94787/non-english Del: in docs -- https://master.php.net/note/delete/94787/in+docs Del: other reasons-- https://master.php.net/note/delete/94787 Reject -- https://master.php.net/note/reject/94787 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#163257) next »