note 56226 deleted from function.gethostbyaddr by mazzanet
| From: | mazzanet@php.net | Date: | Sat, 27 Aug 2005 21:47:22 +0000 |
| Subject: | note 56226 deleted from function.gethostbyaddr by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-94276@lists.php.net to get a copy of this message | ||
Note Submitter: nullmind at gmail dot com
----
If you want to convert the IP to an integer, here is a function to do so. It's faster and
smaller than the previously posted function:
<?php
function ipToInt($ip) {
$octets = explode(".", $ip);
$i = $octets[0] << 24;
$i += $octets[1] << 16;
$i += $octets[2] << 8;
$i += $octets[3];
return($i);
}
function intToIp($dec){
$x0 = ($dec >> 24) & 0xFF;
$x1 = ($dec >> 16) & 0xFF;
$x2 = ($dec >> 8) & 0xFF;
$x3 = $dec & 0xFF;
return("$x0.$x1.$x2.$x3");
}
?>