inet_ntop()


string inet_ntop ( string $str )

Description

inet_ntop() converts a string IP(IPv4/IPv6) address to a human-readable IP address.

※ available F/W version : all

Parameters

Return values

Returns a human-readable IP address string or FALSE on invalid IP address, otherwise: PHP error.

Example

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

$ip6_1 = "1:2:3::4";
hexdump($ip6_1);
// OUTPUT: 0000  31 3a 32 3a 33 3a 3a 34                           |1:2:3::4        |
$ip6_2 = inet_pton($ip6_1);
hexdump($ip6_2);
// OUTPUT: 0000  00 01 00 02 00 03 00 00  00 00 00 00 00 00 00 04  |................|
$ip6_1 = inet_ntop($ip6_2);
hexdump($ip6_1);
// OUTPUT: 0000  31 3a 32 3a 33 3a 3a 34                           |1:2:3::4        |
?>

See also

inet_pton()

Remarks

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