ip2long
Description
The ip2long of Network for PHP converts a string containing an (IPv4) Internet Protocol dotted address into a long integer.
Syntax
ip2long ( string $ip_address ) : int
Parameters
ip_address
A standard format address.
Return
Returns the long integer or FALSE if ip_address is invalid.
Examples
1
<? $ip = gethostbyname('php.net'); $out = "The following URLs are equivalent:<br>\n"; $out .= 'http://php.net/' . "<br>\n"; $out .= 'http://' . $ip . '/' . "<br>\n"; $out .= 'http://' . sprintf("%u", ip2long($ip)) . '/'; echo $out; ?>
The following URLs are equivalent:<br> http://php.net/<br> http://185.85.0.29/<br> http://3109355549/
2
<? $ip = gethostbyname('php.net'); $long = ip2long($ip); if ($long == -1 || $long === FALSE) { echo 'Invalid IP, please try again'; } else { echo $ip . "<br>\n"; echo $long . "<br>\n"; // - on 32-bit systems, due to integer overflow printf("%u\n", ip2long($ip)); } ?>
185.85.0.29<br> 3109355549<br> 3109355549
Links
Network
- checkdnsrr
- closelog
- dns_check_record
- dns_get_mx
- dns_get_record
- fsockopen
- gethostbyaddr
- gethostbyname
- gethostbynamel
- gethostname
- getmxrr
- getprotobyname
- getprotobynumber
- getservbyname
- getservbyport
- header
- header_register_callback
- header_remove
- headers_list
- headers_sent
- http_response_code
- inet_ntop
- inet_pton
- long2ip
- openlog
- pfsockopen
- setcookie
- setrawcookie
- socket_get_status
- socket_set_blocking
- socket_set_timeout
- syslog