Converts a packed internet address to a human readable representation

inet_ntop

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

inet_ntopConverts a packed internet address to a human readable representation

說明

inet_ntop(string $ip): string|false

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.

參數

ip

A 32bit IPv4, or 128bit IPv6 address.

返回值

Returns a string representation of the address 或者在失敗時返回 false.

範例

示例 #1 inet_ntop() Example

<?php
$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;
?>

參見

  • long2ip() - 將長整型轉化為字串形式帶點的網際網路標準格式地址(IPV4)
  • ip2long() - 將 IPV4 的字串網際網路協議轉換成長整型數字
  • inet_pton() - Converts a human readable IP address to its packed in_addr representation

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *