先看如下代码,两个输出结果是一样的:
$dm = 'www.phpfensi.com';
$ip = gethostbyname($dm);
echo gethostbyaddr($ip);
echo $ip;
立即学习“PHP免费学习笔记(深入)”;
关于gethostbyname语法:
string gethostbyname ( string $hostname )
返回由主机名指定的互联网主机的ipv4地址
returns the ipv4 address of the internet host specified by hostname
下面有个例这是最好的方法我已经提出,以解决任何主机名称到ip地址时,它的快速,可靠,已超时的支持,一个无效的地址,例如unicode字符串,返回后4?秒,而不是8调用gethostbyname?它只能与unix虽然,代码如下:
function getaddrbyhost($host, $timeout = 3) {
$query = `nslookup -timeout=$timeout -retry=1 $host`;
if(preg_match('/ address: (.*) /', $query, $matches))
return trim($matches[1]);
return $host;
}
gethostbyaddr 是获取internet主机名对应一个特定的ip地址,代码如下:
string gethostbyaddr ( string $ip_address )
$hostname = gethostbyaddr($_server['remote_addr']);
echo $hostname;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号