gethostbyname 返回主机名对应的 IPv4地址。

发表日期:2021-07-01 08:56:41 | 来源: | | 浏览(880) 分类:网络 函数

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

集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。