PHP inet_pton() Function
The PHP inet_pton() function converts a human readable IPv4 or IPv6 address into a packed 32bit IPv4 or 128bit IPv6 format.
Syntax
inet_pton(ip)
Parameters
ip |
Required. Specify a human readable IPv4 or IPv6 address. |
Return Value
Returns a packed 32bit IPv4 or 128bit IPv6 address on success and FALSE on failure.
Example:
The example below shows the usage of inet_pton() function.
<?php //using inet_pton() function to //convert an IP address $addr1 = inet_pton("112.67.56.45"); $addr2 = inet_pton("91.40.41.93"); $addr3 = inet_pton("57.56.55.54"); $addr4 = inet_pton("126.42.94.96"); //displaying the result echo $addr1."\n"; echo $addr2."\n"; echo $addr3."\n"; echo $addr4."\n"; ?>
The output of the above code will be:
pC8- [()] 9876 ~*^`
❮ PHP Network Reference