inet_pton()


string inet_pton ( string $str )

Description

inet_pton() converts a human-readable IP(IPv4) address to a string

※ available F/W version : all

Parameters

Return values

Returns a string IP address or FALSE when the $str is syntactically invalid, otherwise: PHP error

Example

<?php
$ip1 = "192.168.0.100";
hexdump($ip1);  // OUTPUT: 0000  31 39 32 2e 31 36 38 2e  30 2e 31 30 30           |192.168.0.100   |
$ip2 = inet_pton($ip1);
hexdump($ip2);  // OUTPUT: 0000  c0 a8 00 64                                       |...d            |
$ip1 = inet_ntop($ip2);
hexdump($ip1);  // OUTPUT: 0000  31 39 32 2e 31 36 38 2e  30 2e 31 30 30           |192.168.0.100   |
?>

See also

inet_ntop()

Remarks

This function is identical to the PHP group’s inet_pton().