original_string: public static function cmpIPv4($baseIP, $list) {
  		$IPpartsReq = explode('.', $baseIP);
  		if (count($IPpartsReq) == 4) {
  			$values = self::trimExplode(',', $list, 1);
  
  			foreach ($values as $test) {
  				$testList = explode('/', $test);
  				if (count($testList) == 2) {
  					list($test, $mask) = $testList;
  				} else {
  					$mask = FALSE;
  				}
  
  				if (intval($mask)) {
  						// "192.168.3.0/24"
  					$lnet = ip2long($test);
  					$lip = ip2long($baseIP);
  					$binnet = str_pad(decbin($lnet), 32, '0', STR_PAD_LEFT);
  					$firstpart = substr($binnet, 0, $mask);
  					$binip = str_pad(decbin($lip), 32, '0', STR_PAD_LEFT);
  					$firstip = substr($binip, 0, $mask);
  					$yes = (strcmp($firstpart, $firstip) == 0);
  				} else {
  						// "192.168.*.*"
  					$IPparts = explode('.', $test);
  					$yes = 1;
  					foreach ($IPparts as $index => $val) {
  						$val = trim($val);
  						if (($val !== '*') && ($IPpartsReq[$index] !== $val)) {
  							$yes = 0;
  						}
  					}
  				}
  				if ($yes) {
  					return TRUE;
  				}
  			}
  		}
  		return FALSE;
  	}
code: public static function cmpIPv4($baseIP, $list) {
  		$IPpartsReq = explode('.', $baseIP);
  		if (count($IPpartsReq) == 4) {
  			$values = self::trimExplode(',', $list, 1);
  
  			foreach ($values as $test) {
  				$testList = explode('/', $test);
  				if (count($testList) == 2) {
  					list($test, $mask) = $testList;
  				} else {
  					$mask = FALSE;
  				}
  
  				if (intval($mask)) {
  						// "192.168.3.0/24"
  					$lnet = ip2long($test);
  					$lip = ip2long($baseIP);
  					$binnet = str_pad(decbin($lnet), 32, '0', STR_PAD_LEFT);
  					$firstpart = substr($binnet, 0, $mask);
  					$binip = str_pad(decbin($lip), 32, '0', STR_PAD_LEFT);
  					$firstip = substr($binip, 0, $mask);
  					$yes = (strcmp($firstpart, $firstip) == 0);
  				} else {
  						// "192.168.*.*"
  					$IPparts = explode('.', $test);
  					$yes = 1;
  					foreach ($IPparts as $index => $val) {
  						$val = trim($val);
  						if (($val !== '*') && ($IPpartsReq[$index] !== $val)) {
  							$yes = 0;
  						}
  					}
  				}
  				if ($yes) {
  					return TRUE;
  				}
  			}
  		}
  		return FALSE;
  	}
code_tokens: public static function cmpIPv4 ( $ baseIP , $ list ) { $ IPpartsReq = explode ( '.' , $ baseIP ) ; if ( count ( $ IPpartsReq ) == 4 ) { $ values = self :: trimExplode ( ',' , $ list , 1 ) ; foreach ( $ values as $ test ) { $ testList = explode ( '/' , $ test ) ; if ( count ( $ testList ) == 2 ) { list ( $ test , $ mask ) = $ testList ; } else { $ mask = FALSE ; } if ( intval ( $ mask ) ) { // "192.168.3.0/24" $ lnet = ip2long ( $ test ) ; $ lip = ip2long ( $ baseIP ) ; $ binnet = str_pad ( decbin ( $ lnet ) , 32 , '0' , STR_PAD_LEFT ) ; $ firstpart = substr ( $ binnet , 0 , $ mask ) ; $ binip = str_pad ( decbin ( $ lip ) , 32 , '0' , STR_PAD_LEFT ) ; $ firstip = substr ( $ binip , 0 , $ mask ) ; $ yes = ( strcmp ( $ firstpart , $ firstip ) == 0 ) ; } else { // "192.168.*.*" $ IPparts = explode ( '.' , $ test ) ; $ yes = 1 ; foreach ( $ IPparts as $ index => $ val ) { $ val = trim ( $ val ) ; if ( ( $ val !== '*' ) && ( $ IPpartsReq [ $ index ] !== $ val ) ) { $ yes = 0 ; } } } if ( $ yes ) { return TRUE ; } } } return FALSE ; }
docstring: Match IPv4 number with list of numbers with wildcard
  
  @param	string		$baseIP is the current remote IP address for instance, typ. REMOTE_ADDR
  @param	string		$list is a comma-list of IP-addresses to match with. *-wildcard allowed instead of number, plus leaving out parts in the IP number is accepted as wildcard (eg. 192.168.*.* equals 192.168), could also contain IPv6 addresses
  @return	boolean		TRUE if an IP-mask from $list matches $baseIP
docstring_tokens: Match IPv4 number with list of numbers with wildcard