note 44013 added to function.gethostbyaddr
| From: | eternal at 1337 dot li | Date: | Mon, 12 Jul 2004 15:47:18 +0000 |
| Subject: | note 44013 added to function.gethostbyaddr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73101@lists.php.net to get a copy of this message | ||
By getting the name for the ip, the name includes the suffix (ie pc1.home.lan). But I wanted to use
only the name, here's my script (very simple) - i'm too lazy to build a function:
$ip = "192.168.0.1";
$dns = gethost($ip);
$pos = strpos($dns, ".");
$name = substr($dns, 0, $pos);
echo $name;
/*gethostbyaddr() tends to lag on various systems
if your server is on a *nix system, this is faster*/
function gethost ($ip) {
$host =
host $ip;
return (($host ? end ( explode (' ', $host)) : $ip));
}
----
Manual Page -- http://www.php.net/manual/en/function.gethostbyaddr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44013
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44013&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44013&report=yes
Search -- http://master.php.net/manage/user-notes.php