Add glob() compat for php < 4.3.0
git-svn-id: https://develop.svn.wordpress.org/trunk@3198 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c29812748d
commit
3b4d47257d
|
@ -89,4 +89,68 @@ if (!function_exists('array_change_key_case')) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Added in PHP 4.3.0 */
|
||||||
|
|
||||||
|
if( !(function_exists('glob')) ):
|
||||||
|
function glob($pattern) {
|
||||||
|
// get pathname (everything up until the last / or \)
|
||||||
|
$path=$output=null;
|
||||||
|
// if(PHP_OS=='WIN32')
|
||||||
|
// $slash='\\';
|
||||||
|
// else
|
||||||
|
// $slash='/';
|
||||||
|
$slash = '/';
|
||||||
|
$lastpos=strrpos($pattern,$slash);
|
||||||
|
if(!($lastpos===false)) {
|
||||||
|
$path=substr($pattern,0,$lastpos); #negative length means take from the right
|
||||||
|
$pattern=substr($pattern,$lastpos+1);
|
||||||
|
} else {
|
||||||
|
//no dir info, use current dir
|
||||||
|
$path=getcwd();
|
||||||
|
}
|
||||||
|
$handle=@ opendir($path);
|
||||||
|
if($handle===false)
|
||||||
|
return false;
|
||||||
|
while($dir=readdir($handle)) {
|
||||||
|
if ( '.' == $dir || '..' == $dir )
|
||||||
|
continue;
|
||||||
|
if (pattern_match($pattern,$dir))
|
||||||
|
$output[]=$path . '/' . $dir;
|
||||||
|
}
|
||||||
|
closedir($handle);
|
||||||
|
print_r($output);
|
||||||
|
if(is_array($output))
|
||||||
|
return $output;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function pattern_match($pattern,$string) {
|
||||||
|
// basically prepare a regular expression
|
||||||
|
$out=null;
|
||||||
|
$chunks=explode(';',$pattern);
|
||||||
|
foreach($chunks as $pattern) {
|
||||||
|
$escape=array('$','^','.','{','}','(',')','[',']','|');
|
||||||
|
while(strpos($pattern,'**')!==false)
|
||||||
|
$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(eregi("^$out[0]$",$string));
|
||||||
|
else
|
||||||
|
foreach($out as $tester)
|
||||||
|
if(eregi("^$tester$",$string))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
endif;
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue