note 32772 added to function.is-numeric

From: Date: Fri, 06 Jun 2003 15:01:16 +0000
Subject: note 32772 added to function.is-numeric
Groups: php.notes 
Request: Send a blank email to php-notes+get-49881@lists.php.net to get a copy of this message
I've seen a couple of functions here that destinguish an IP from any other input. Although mine isn't very different, it checks for... - numeric input - valid numbers (> 0 && < 256) - 4 parts (111.222.333.444) ...and returns true or false. <? function is_ip($value) { $parts = split('\.', $value); if(count($parts) == 4) { foreach($parts as $part) { if((!is_null($part)) && ($part < 0 || $part > 255) || !is_numeric($part)) { return false; } } return true; } return false; } $ip = '212.74.53.102'; echo $ip."<br>"; if(is_ip($ip) == true) { echo "It's an IP"; } else { echo "I don't know that it is, but it sure isn't a valid IP"; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.is-numeric.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32772 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32772&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32772&report=yes

« previous php.notes (#49881) next »