note 17580 added to ref.network

From: Date: Sat, 15 Dec 2001 00:46:14 +0000
Subject: note 17580 added to ref.network
Groups: php.notes 
Request: Send a blank email to php-notes+get-22828@lists.php.net to get a copy of this message
PHP miss CIDR functions. This one will convert a CIDR like this: 0.0.0.0/16 -> 0.0.0.0 - 0.0.255.255 127.0/16 -> 127.0.0.0 - 127.0.255.255 etc... function cidrconv($net) { $start=strtok($net,"/"); $n=3-substr_count($net, "."); if ($n>0) { for ($i=$n;$i>0;$i--) $start.=".0"; } $bits1=str_pad(decbin(ip2long($start)),32,"0","STR_PAD_LEFT"); $net=pow(2,(32-substr(strstr($net,"/"),1)))-1; $bits2=str_pad(decbin($net),32,"0","STR_PAD_LEFT"); for ($i=0;$i<32;$i++) { if ($bits1[$i]==$bits2[$i]) $final.=$bits1[$i]; if ($bits1[$i]==1 and $bits2[$i]==0) $final.=$bits1[$i]; if ($bits1[$i]==0 and $bits2[$i]==1) $final.=$bits2[$i]; } return $start." - ".long2ip(bindec($final)); } -- http://www.php.net/manual/en/ref.network.php http://master.php.net/manage/user-notes.php?action=edit+17580 http://master.php.net/manage/user-notes.php?action=delete+17580 http://master.php.net/manage/user-notes.php?action=reject+17580

« previous php.notes (#22828) next »