gethostbyname

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

gethostbyname 返回主機(jī)名對應(yīng)的 IPv4地址。

說明

gethostbyname(string $hostname): string

返回主機(jī)名 hostname 對應(yīng)的 IPv4 互聯(lián)網(wǎng)地址。

參數(shù)

hostname

主機(jī)名

返回值

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

范例

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

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

echo 
$ip;
?>

參見

  • gethostbyaddr() - 獲取指定的IP地址對應(yīng)的主機(jī)名
  • gethostbynamel() - 獲取互聯(lián)網(wǎng)主機(jī)名對應(yīng)的 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