Пример #1
0
 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);
     if (is_array($output)) {
         return $output;
     }
     return false;
 }
Пример #2
0
 /**
  *  To define glob() function if not exists
  */
 function glob($pattern)
 {
     #get pathname (everything up until the last / or \)
     $path = $output = null;
     if (PHP_OS == 'WIN32') {
         $slash = '\\';
     } else {
         $slash = '/';
     }
     $lastpos = strrpos($pattern, $slash);
     if (!($lastpos === false)) {
         $path = substr($pattern, 0, -$lastpos - 1);
         $pattern = substr($pattern, $lastpos);
     } else {
         #no dir info, use current dir
         $path = getcwd();
     }
     $handle = @opendir($path);
     if ($handle === false) {
         return false;
     }
     while ($dir = readdir($handle)) {
         if (pattern_match($pattern, $dir)) {
             $output[] = $dir;
         }
     }
     closedir($handle);
     if (is_array($output)) {
         return $output;
     }
     return false;
 }