PHP inet_ntop() Function
The PHP inet_ntop() function converts a 32bit IPv4 or 128bit IPv6 address into a readable format.
Syntax
inet_ntop(ip)
Parameters
ip |
Required. Specify a 32bit IPv4 or 128bit IPv6 address. |
Return Value
Returns a string representation of the address or false on failure.
Example:
The example below shows the usage of inet_ntop() function.
<?php //storing the address in a variable $packed_addr = chr(127) . chr(0) . chr(0) . chr(1); //using inet_ntop() function to convert this //address to a human readable format $expanded_addr = inet_ntop($packed_addr); //displaying the result echo $expanded_addr; ?>
The output of the above code will be:
127.0.0.1
Example:
The inet_ntop() function uses a string of size 4 of ASCII characters as the parameter and converts it into the human readable format. Consider the example below:
<?php //using inet_ntop() function to convert this //address to a human readable format echo inet_ntop("[()]")."\n"; echo inet_ntop("9876")."\n"; echo inet_ntop("~*^`")."\n"; echo inet_ntop("ABCD")."\n"; echo inet_ntop("&^%$")."\n"; ?>
The output of the above code will be:
91.40.41.93 57.56.55.54 126.42.94.96 65.66.67.68 38.94.37.36
❮ PHP Network Reference