返回主機名對應的 IPv4地址。

gethostbyname

(PHP 4, PHP 5, PHP 7, PHP 8)

gethostbyname 返回主機名對應的 IPv4地址。

說明

gethostbyname(string $hostname): string

返回主機名 hostname 對應的 IPv4 網際網路地址。

參數

hostname

主機名

返回值

成功時返回 IPv4 地址,失敗時原封不動返回 hostname 字串。

範例

示例 #1 簡單的 gethostbyname() 例子

<?php
$ip 
gethostbyname('www.example.com');

echo 
$ip;
?>

參見

  • gethostbyaddr() - 獲取指定的IP地址對應的主機名
  • gethostbynamel() - 獲取網際網路主機名對應的 IPv4 地址列表
  • inet_pton() - Converts a human readable IP address to its packed in_addr representation
  • inet_ntop() - Converts a packed internet address to a human readable representation

發佈留言

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