cvs: pear /Net_CheckIP CheckIP.php

From: Date: Sat, 17 Aug 2002 09:41:24 +0000
Subject: cvs: pear /Net_CheckIP CheckIP.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-5777@lists.php.net to get a copy of this message
mj Sat Aug 17 05:41:24 2002 EDT Modified files: /pear/Net_CheckIP CheckIP.php Log: * Remove dependency for regular expressions. # Patch by: Eric <eric@ypass.net> Index: pear/Net_CheckIP/CheckIP.php diff -u pear/Net_CheckIP/CheckIP.php:1.4 pear/Net_CheckIP/CheckIP.php:1.5 --- pear/Net_CheckIP/CheckIP.php:1.4 Tue Dec 11 14:45:49 2001 +++ pear/Net_CheckIP/CheckIP.php Sat Aug 17 05:41:24 2002 @@ -17,14 +17,14 @@ // | Guido Haeger <gh-lists@ecora.de> | // +----------------------------------------------------------------------+ // -// $Id: CheckIP.php,v 1.4 2001/12/11 19:45:49 sebastian Exp $ +// $Id: CheckIP.php,v 1.5 2002/08/17 09:41:24 mj Exp $ /** * Class to validate the syntax of IPv4 adresses * * Usage: * <?php -* require_once "Net_CheckIP/CheckIP.php"; +* require_once "Net/CheckIP.php"; * * if (Net_CheckIP::check_ip("your_ip_goes_here")) { * // Syntax of the IP is ok @@ -34,7 +34,7 @@ * @author Martin Jansen <mj@php.net> * @author Guido Haeger <gh-lists@ecora.de> * @package Net_CheckIP -* @version 1.0 +* @version 1.1 * @access public */ class Net_CheckIP @@ -43,9 +43,9 @@ /** * Validate the syntax of the given IP adress * - * This function splits the IP adress in 4 pieces + * This function splits the IP address in 4 pieces * (separated by ".") and checks for each piece - * if it's and integer value between 0 and 255. + * if it's an integer value between 0 and 255. * If all 4 parameters pass this test, the function * returns true. * @@ -54,23 +54,22 @@ */ function check_ip($ip) { + $oct = explode('.', $ip); + if (count($oct) != 4) { + return false; + } - $count = 0; - - $x = explode(".", $ip); - $max = count($x); + for ($i = 0; $i < 4; $i++) { + if (!is_numeric($oct[$i])) { + return false; + } - for ($i = 0; $i < $max; $i++) { - if ($x[$i] >= 0 && $x[$i] <= 255 && preg_match("/^\d{1,3}$/", $x[$i])) { - $count++; + if ($oct[$i] < 0 || $oct[$i] > 255) { + return false; } } - if ($count == 4 && $max == 4) { - return true; - } else { - return false; - } + return true; } } ?>

« previous php.pear.cvs (#5777) next »