ftp_base::glob_pattern_match()publicWP 1.0

Method of the class: ftp_base{}

No Hooks.

Return

null. Nothing (null).

Usage

$ftp_base = new ftp_base();
$ftp_base->glob_pattern_match( $pattern, $subject );
$pattern (required)
-
$subject (required)
-

ftp_base::glob_pattern_match() code WP 6.5.4

function glob_pattern_match($pattern,$subject) {
	$out=null;
	$chunks=explode(';',$pattern);
	foreach($chunks as $pattern) {
		$escape=array('$','^','.','{','}','(',')','[',']','|');
		while(str_contains($pattern,'**'))
			$pattern=str_replace('**','*',$pattern);
		foreach($escape as $probe)
			$pattern=str_replace($probe,"\\$probe",$pattern);
		$pattern=str_replace('?*','*',
			str_replace('*?','*',
				str_replace('*',".*",
					str_replace('?','.{1,1}',$pattern))));
		$out[]=$pattern;
	}
	if(count($out)==1) return($this->glob_regexp("^$out[0]$",$subject));
	else {
		foreach($out as $tester)
			// TODO: This should probably be glob_regexp(), but needs tests.
			if($this->my_regexp("^$tester$",$subject)) return true;
	}
	return false;
}