note 47659 deleted from function.eregi by cmb

From: Date: Sun, 20 Oct 2019 08:44:29 +0000
Subject: note 47659 deleted from function.eregi by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212681@lists.php.net to get a copy of this message
Note Submitter: cristian81 AT katamail DOT com ---- 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; } ?>

« previous php.notes (#212681) next »