inet_ntop()
inet_ntop() — Converts a packed internet address to a human readable representation.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.1.0, 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
This function converts a 32bit IPv4, or 128bit IPv6 address (if PHP was built with IPv6 support enabled) into an address family appropriate string representation.
Signature
inet_ntop(string $ip): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $ip | string | A 32bit IPv4, or 128bit IPv6 address. |
Return value
Returns a string representation of the address or false on failure.
Example
A runnable snippet:
$packed = chr(127) . chr(0) . chr(0) . chr(1); $expanded = inet_ntop($packed); /* Outputs: 127.0.0.1 */ echo $expanded; $packed = str_repeat(chr(0), 15) . chr(1); $expanded = inet_ntop($packed); /* Outputs: ::1 */ echo $expanded;
See also
long2ip(), ip2long(), inet_pton()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page inet_ntop() (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.