note 20116 added to function.is-numeric

From: Date: Fri, 22 Mar 2002 19:31:08 +0000
Subject: note 20116 added to function.is-numeric
Groups: php.notes 
Request: Send a blank email to php-notes+get-28086@lists.php.net to get a copy of this message
I made this function to check IP's so not to get the a.b.c format warning in the gethostbyaddr() function PHP4. It's basic but solved the is_numeric() multi-[.] problem. <?php function is_ip($ip) { $valid = true; $ip = explode(".", $ip); foreach($ip as $block) { if(!is_numeric($block)) { $valid = false; } } return $valid; } ?> returns true if the string does not contain anything outside the is_numeric() restraints else returns false. NOTE: this does't validate for full ip's only for the elements. That could be added easily however. ENJOY! -- http://www.php.net/manual/en/function.is-numeric.php http://master.php.net/manage/user-notes.php?action=edit+20116 http://master.php.net/manage/user-notes.php?action=delete+20116 http://master.php.net/manage/user-notes.php?action=reject+20116

« previous php.notes (#28086) next »