Skip to content
Browse files

* Remove dependency for regular expressions.

# Patch by: Eric <eric@ypass.net>


git-svn-id: http://svn.php.net/repository/pear/packages/Net_CheckIP/trunk@92353 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 764d14f commit 7a269890882f0af6b64620cfe406700e19550c5b @mj mj committed Aug 17, 2002
Showing with 15 additions and 16 deletions.
  1. +15 −16 CheckIP.php
View
31 CheckIP.php
@@ -24,7 +24,7 @@
*
* 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 @@ class Net_CheckIP
/**
* 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 @@ class Net_CheckIP
*/
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;
}
}
?>

0 comments on commit 7a26989

Please sign in to comment.
Something went wrong with that request. Please try again.