| | 92 | /* Added in PHP 4.3.0 */ |
|---|
| | 93 | |
|---|
| | 94 | if( !(function_exists('glob')) ): |
|---|
| | 95 | function glob($pattern) { |
|---|
| | 96 | // get pathname (everything up until the last / or \) |
|---|
| | 97 | $path=$output=null; |
|---|
| | 98 | // if(PHP_OS=='WIN32') |
|---|
| | 99 | // $slash='\\'; |
|---|
| | 100 | // else |
|---|
| | 101 | // $slash='/'; |
|---|
| | 102 | $slash = '/'; |
|---|
| | 103 | $lastpos=strrpos($pattern,$slash); |
|---|
| | 104 | if(!($lastpos===false)) { |
|---|
| | 105 | $path=substr($pattern,0,$lastpos); #negative length means take from the right |
|---|
| | 106 | $pattern=substr($pattern,$lastpos+1); |
|---|
| | 107 | } else { |
|---|
| | 108 | //no dir info, use current dir |
|---|
| | 109 | $path=getcwd(); |
|---|
| | 110 | } |
|---|
| | 111 | $handle=@ opendir($path); |
|---|
| | 112 | if($handle===false) |
|---|
| | 113 | return false; |
|---|
| | 114 | while($dir=readdir($handle)) { |
|---|
| | 115 | if ( '.' == $dir || '..' == $dir ) |
|---|
| | 116 | continue; |
|---|
| | 117 | if (pattern_match($pattern,$dir)) |
|---|
| | 118 | $output[]=$path . '/' . $dir; |
|---|
| | 119 | } |
|---|
| | 120 | closedir($handle); |
|---|
| | 121 | print_r($output); |
|---|
| | 122 | if(is_array($output)) |
|---|
| | 123 | return $output; |
|---|
| | 124 | |
|---|
| | 125 | return false; |
|---|
| | 126 | } |
|---|
| | 127 | |
|---|
| | 128 | function pattern_match($pattern,$string) { |
|---|
| | 129 | // basically prepare a regular expression |
|---|
| | 130 | $out=null; |
|---|
| | 131 | $chunks=explode(';',$pattern); |
|---|
| | 132 | foreach($chunks as $pattern) { |
|---|
| | 133 | $escape=array('$','^','.','{','}','(',')','[',']','|'); |
|---|
| | 134 | while(strpos($pattern,'**')!==false) |
|---|
| | 135 | $pattern=str_replace('**','*',$pattern); |
|---|
| | 136 | foreach($escape as $probe) |
|---|
| | 137 | $pattern=str_replace($probe,"\\$probe",$pattern); |
|---|
| | 138 | |
|---|
| | 139 | $pattern=str_replace('?*','*', |
|---|
| | 140 | str_replace('*?','*', |
|---|
| | 141 | str_replace('*',".*", |
|---|
| | 142 | str_replace('?','.{1,1}',$pattern)))); |
|---|
| | 143 | $out[]=$pattern; |
|---|
| | 144 | } |
|---|
| | 145 | |
|---|
| | 146 | if(count($out)==1) |
|---|
| | 147 | return(eregi("^$out[0]$",$string)); |
|---|
| | 148 | else |
|---|
| | 149 | foreach($out as $tester) |
|---|
| | 150 | if(eregi("^$tester$",$string)) |
|---|
| | 151 | return true; |
|---|
| | 152 | return false; |
|---|
| | 153 | } |
|---|
| | 154 | endif; |
|---|
| | 155 | |
|---|