note 25047 added to function.is-numeric

From: Date: Mon, 09 Sep 2002 10:46:41 +0000
Subject: note 25047 added to function.is-numeric
Groups: php.notes 
Request: Send a blank email to php-notes+get-36381@lists.php.net to get a copy of this message
This is going off on a tangent slightly but as it has been mentioned before I thought it might be an idea to add this, this is the function I use to verify the validity of IP address (takes only one input, the IP address string) function ip_check($ip) { $ip_array = explode(".", $ip); if (count($ip_array) <> 4) { $error = true; } for ($loop = 0; $loop < 4; $loop++) { if (is_numeric($ip_array[$loop]) != true) { $error = true; } if (strlen($ip_array[$loop]) > 3) { $error = true; } if ($ip_array[$loop] > 254) { $error = true; } if (($loop == 0) OR ($loop == 3)) { if ($ip_array[$loop] < 1) { $error = true; } } else { if ($ip_array[$loop] < 0) { $error = true; } } } There are probably a 101 other ways of doing this, but this one has worked for me -- http://www.php.net/manual/en/function.is-numeric.php http://master.php.net/manage/user-notes.php?action=edit+25047 http://master.php.net/manage/user-notes.php?action=delete+25047 http://master.php.net/manage/user-notes.php?action=reject+25047

« previous php.notes (#36381) next »