ip2long()
ip2long() — Converts a string containing an (IPv4) Internet Protocol dotted address into a long integer.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
The function ip2long() generates a long integer representation of IPv4 Internet network address from its Internet standard format (dotted string) representation.
Signature
ip2long(string $ip): int|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $ip | string | A standard format address. |
Return value
Returns the long integer or false if ip is invalid.
Example
A runnable snippet:
$ip = gethostbyname('www.example.com'); $out = "The following URLs are equivalent:<br />\n"; $out .= 'http://www.example.com/, http://' . $ip . '/, and http://' . sprintf("%u", ip2long($ip)) . "/<br />\n"; echo $out;
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page ip2long() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.