note 47892 added to function.gethostbynamel

From: Date: Sat, 04 Dec 2004 01:39:57 +0000
Subject: note 47892 added to function.gethostbynamel
Groups: php.notes 
Request: Send a blank email to php-notes+get-81349@lists.php.net to get a copy of this message
This is a replacement for gethostbynamel(), for *nix only, which uses the "host" program to lookup hostnames. Most people won't need this, but I had a temporary server problem where all the PHP DNS lookup functions were failing, so this works as a direct replacement: function SafeGetHostByNameL($hostname) { if (false) { // put conditional check here to use normal gethostbynamel() return gethostbynamel($hostname); } elseif (ereg('[0-9]{1,3}(\.[0-9]{1,3}){3}', $hostname)) { return array($hostname); } else { $response = trim(host $hostname); if (preg_match_all('/([a-z0-9\.\-]* is an alias for ([a-z0-9\.\-]*)\.['." \r\n".']+)*[a-z0-9\.\-]* has address ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/', trim($response), $matches, PREG_PATTERN_ORDER)) { return $matches[3]; } elseif (eregi('^Host '.$hostname.' not found', $response, $matches)) { return false; } } return false; } ---- Manual Page -- http://www.php.net/manual/en/function.gethostbynamel.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47892 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47892&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47892&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47892&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47892&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47892&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47892&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47892&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81349) next »