note 47659 added to function.eregi

From: Date: Wed, 24 Nov 2004 11:12:41 +0000
Subject: note 47659 added to function.eregi
Groups: php.notes 
Request: Send a blank email to php-notes+get-80966@lists.php.net to get a copy of this message
The same "checkipaddress" function posted by "lueck at gerwan dot de", with the add of an optional jolly char suport. Returns TRUE or FALSE Results: check_ip_address('125.32.15.0') is TRUE check_ip_address('125.32.15.*') is FALSE check_ip_address('125.32.15.*', '*') is TRUE check_ip_address('*.*.*.*', '*') is TRUE check_ip_address('125.-.15.2', '-') is TRUE <?php function check_ip_address($checkip, $jolly_char='') { if ($jolly_char=='.') // dot ins't allowed as jolly char $jolly_char = ''; if ($jolly_char!='') { $checkip = str_replace($jolly_char, '*', $checkip); // replace the jolly char with an asterisc $my_reg_expr = "^[0-9\*]{1,3}\.[0-9\*]{1,3}\.[0-9\*]{1,3}\.[0-9\*]{1,3}$"; $jolly_char = '*'; } else $my_reg_expr = "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"; if (eregi($my_reg_expr, $checkip)) { for ($i = 1; $i <= 3; $i++) { if (!(substr($checkip, 0, strpos($checkip, ".")) >= "0" && substr($checkip, 0, strpos($checkip, ".")) <= "255")) { if ($jolly_char!='') { // if exists, check for the jolly char if (substr($checkip, 0, strpos($checkip, "."))!=$jolly_char) return false; } else return false; } $checkip = substr($checkip, strpos($checkip, ".") + 1); } if (!($checkip >= "0" && $checkip <= "255")) { // class D if ($jolly_char!='') { // if exists, check for the jolly char if ($checkip!=$jolly_char) return false; } else return false; } } else return false; return true; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.eregi.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47659 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47659&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47659&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47659&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47659&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47659&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47659&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47659&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#80966) next »