note 56226 added to function.gethostbyaddr
| From: | nullmind at gmail dot com | Date: | Sat, 27 Aug 2005 21:26:43 +0000 |
| Subject: | note 56226 added to function.gethostbyaddr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94271@lists.php.net to get a copy of this message | ||
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");
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.gethostbyaddr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56226
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56226&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56226&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56226&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56226&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56226&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56226&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56226&report=yes
Search -- http://master.php.net/manage/user-notes.php