php主机域名,PHP获取主机名、域名函数

今天看到几个函数,可以根据ip地址 / 域名 获取对应的 域名 / ip 的函数。记录于此。 gethostbynamel($hostname) // 根据 域名 获取 IP,返回一个数组,比如baidu。com,就返回2个ip 说明array gethostbynamel ( string $hostname )Returns a list of IPv4 a

今天看到几个函数,可以根据ip地址  /  域名 获取对应的 域名 / ip 的函数。记录于此。

gethostbynamel($hostname) // 根据域名获取IP,返回一个数组,比如baidu。com,就返回2个ip

说明

array gethostbynamel ( string $hostname )

Returns a list of IPv4 addresses to which the Internet host specified by hostname resolves.

参数

hostname The host name.

返回值

Returns an array of IPv4 addresses or FALSE if hostname could not be resolved.

gethostbyname($hostname) // 根据域名获取IP,只返回第一个IP

gethostbyname — Get the IPv4 address corresponding to a given Internet host name

说明

string gethostbyname ( string $hostname )

Returns the IPv4 address of the Internet host specified by hostname.

参数

hostname The host name.

返回值

Returns the IPv4 address or a string containing the unmodified hostname on failure.

gethostbyaddr($ip)  // 根据IP 获取域名

gethostbyaddr — Get the Internet host name corresponding to a given IP address

说明

string gethostbyaddr ( string $ip_address )

Returns the host name of the Internet host specified by ip_address.

参数

ip_address

The host IP address.

返回值

Returns the host name on success, the unmodified ip_address on failure, or FALSE on malformed input.

例子:

$hostname = 'www.baidu.com';$addr = '127.0.0.1';print_r(gethostbyname($hostname));echo '
';print_r(gethostbyaddr($addr));echo '
';print_r(gethostbynamel($hostname));

输出

220.181.111.148

idc-wang

Array ( [0] => 220.181.111.148 [1] => 220.181.112.143 )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值