當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SpoonFilter::isValidRegexp方法代碼示例

本文整理匯總了PHP中SpoonFilter::isValidRegexp方法的典型用法代碼示例。如果您正苦於以下問題:PHP SpoonFilter::isValidRegexp方法的具體用法?PHP SpoonFilter::isValidRegexp怎麽用?PHP SpoonFilter::isValidRegexp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SpoonFilter的用法示例。


在下文中一共展示了SpoonFilter::isValidRegexp方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getList

 /**
  * Returns a list of directories within a directory.
  *
  * @return	array								An array containing all directories (and files if $showFiles is true).
  * @param	string $path						Path of the directory.
  * @param	bool[optional] $showFiles			Should files be included in the list.
  * @param	array[optional] $excluded			An array containing directories/files to exclude.
  * @param 	string[optional] $includeRegexp		An regular expression that represents the directories/files to include in the list. Other directories will be excluded.
  */
 public static function getList($path, $showFiles = false, array $excluded = null, $includeRegexp = null)
 {
     // redefine arguments
     $path = (string) $path;
     $showFiles = (bool) $showFiles;
     // validate regex
     if ($includeRegexp !== null) {
         // redefine
         $includeRegexp = (string) $includeRegexp;
         // validate
         if (!SpoonFilter::isValidRegexp($includeRegexp)) {
             throw new SpoonDirectoryException('Invalid regular expression (' . $includeRegexp . ').');
         }
     }
     // define file list
     $directories = array();
     // directory exists
     if (self::exists($path)) {
         // attempt to open directory
         $directory = @opendir($path);
         // do your thing if directory-handle isn't false
         if ($directory !== false) {
             // start reading
             while (($file = readdir($directory)) !== false) {
                 // no '.' and '..' and it's a file
                 if ($file != '.' && $file != '..') {
                     // directory
                     if (is_dir($path . '/' . $file)) {
                         // exclude certain files
                         if (count($excluded) != 0) {
                             if (!in_array($file, $excluded)) {
                                 if ($includeRegexp !== null) {
                                     // init var
                                     $matches = array();
                                     // is this a match?
                                     if (preg_match($includeRegexp, $file, $matches) != 0) {
                                         $directories[] = $file;
                                     }
                                 } else {
                                     $directories[] = $file;
                                 }
                             }
                         } else {
                             if ($includeRegexp !== null) {
                                 // init var
                                 $matches = array();
                                 // is this a match?
                                 if (preg_match($includeRegexp, $file, $matches) != 0) {
                                     $directories[] = $file;
                                 }
                             } else {
                                 $directories[] = $file;
                             }
                         }
                     } else {
                         // show files
                         if ($showFiles) {
                             // exclude certain files
                             if (count($excluded) != 0) {
                                 if (!in_array($file, $excluded)) {
                                     $directories[] = $file;
                                 }
                             } else {
                                 $directories[] = $file;
                             }
                         }
                     }
                 }
             }
         }
         // close directory
         @closedir($directory);
     }
     // cough up directory listing
     natsort($directories);
     return $directories;
 }
開發者ID:JonckheereM,項目名稱:Public,代碼行數:86,代碼來源:directory.php

示例2: testIsValidRegexp

 public function testIsValidRegexp()
 {
     $this->assertTrue(SpoonFilter::isValidRegexp('/boobies/'));
 }
開發者ID:jeroendesloovere,項目名稱:library,代碼行數:4,代碼來源:SpoonFilterTest.php

示例3: getList

 /**
  * Retrieves a list of files within a directory.
  *
  * @return	array								An array containing a list of files in the given directory.
  * @param	string $path						The path to the directory.
  * @param	string[optional] $includeRegexp		A regular expresion that filters the files that should be included in the list.
  */
 public static function getList($path, $includeRegexp = null)
 {
     // redefine arguments
     $path = (string) $path;
     // validate regex
     if ($includeRegexp !== null) {
         // redefine
         $includeRegexp = (string) $includeRegexp;
         // validate
         if (!SpoonFilter::isValidRegexp($includeRegexp)) {
             throw new SpoonFileSystemException('Invalid regular expression (' . $includeRegexp . ')');
         }
     }
     // define list
     $files = array();
     // directory exists
     if (SpoonDirectory::exists($path)) {
         // attempt to open directory
         if ($directory = @opendir($path)) {
             // start reading
             while (($file = readdir($directory)) !== false) {
                 // no '.' and '..' and it's a file
                 if ($file != '.' && $file != '..' && is_file($path . '/' . $file)) {
                     // is there a include-pattern?
                     if ($includeRegexp !== null) {
                         // init var
                         $matches = array();
                         // is this a match?
                         if (preg_match($includeRegexp, $file, $matches) != 0) {
                             $files[] = $file;
                         }
                     } else {
                         $files[] = $file;
                     }
                 }
             }
         }
         // close directory
         @closedir($directory);
     }
     // directory doesn't exist or a problem occured
     return $files;
 }
開發者ID:ss23,項目名稱:ECommerce,代碼行數:50,代碼來源:filesystem.php


注:本文中的SpoonFilter::isValidRegexp方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。