note 15386 added to function.ip2long
| From: | mlong at mlong dot org | Date: | Fri, 07 Sep 2001 17:09:31 +0000 |
| Subject: | note 15386 added to function.ip2long | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17778@lists.php.net to get a copy of this message | ||
I wrote my own before I discovered this function so here is a functional equivalent (in all my tests
anyways):
$iparr=explode('.',$ip);
$iparrsize=count($iparr);
reset($iparr);
for ($ct=0; $ct < $iparrsize; $ct++)
{
$iparr[$ct] =ereg_replace("[^[:digit:]]","",$iparr[$ct]);
$iparr[$ct] = sprintf("%x",$iparr[$ct]);
if (strlen($iparr[$ct]) == 1) { $iparr[$ct] ="0$iparr[$ct]"; }
if ($iparr[$ct] == "") { return 0; }
}
$long = hexdec(join('',$iparr));
http://www.php.net/manual/en/function.ip2long.php