当前位置: 首页>>代码示例>>PHP>>正文


PHP filesystem::file_extension方法代码示例

本文整理汇总了PHP中filesystem::file_extension方法的典型用法代码示例。如果您正苦于以下问题:PHP filesystem::file_extension方法的具体用法?PHP filesystem::file_extension怎么用?PHP filesystem::file_extension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在filesystem的用法示例。


在下文中一共展示了filesystem::file_extension方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: search_files

 /**
  * @en Find files
  * @ru Поиск файлов
  *
  * # listing all the files in a directory and subdirectories:
  *
  * $result = filesystem::scandir('./src/lib/'); # Array
  *                                              # (
  *                                              #     [0] => src/lib/include.php
  *                                              #     [1] => src/lib/README.md
  *                                              #     [2] => src/lib/src/etc/rude-system.php
  *                                              #     [3] => src/lib/src/etc/rude-globals.php
  *                                              #     [4] => src/lib/src/etc/rude-measures.php
  *                                              #     [5] => src/lib/src/etc/rude-visitor.php
  *                                              #     [6] => src/lib/src/etc/rude-date.php
  *                                              #     [7] => src/lib/src/etc/rude-url.php
  *                                              #     [8] => src/lib/src/etc/rude-html.php
  *                                              #     [9] => src/lib/src/etc/rude-crypt.php
  *                                              #     [10] => src/lib/src/etc/rude-cookies.php
  *                                              #     [11] => src/lib/src/etc/rude-math.php
  *                                              #     [12] => src/lib/src/etc/rude-autoload.php
  *                                              #     [13] => src/lib/src/etc/rude-headers.php
  *                                              #     [14] => src/lib/src/etc/rude-speedtest.php
  *                                              #     [15] => src/lib/src/etc/rude-curl.php
  *                                              #     [16] => src/lib/src/etc/rude-filesystem.php
  *                                              #     [17] => src/lib/src/etc/rude-session.php
  *                                              #
  *                                              #     ... and 164 files more
  *                                              # )
  *
  *
  * # listing all the files in a directory and subdirectories with '.md' file extension:
  *
  * $result = filesystem::scandir('src/lib', 'md'); # Array
  *                                                 # (
  *                                                 #     [0] => src/lib/README.md
  *                                                 #     [1] => src/lib/LICENSE.md
  *                                                 #     [2] => src/lib/NOTICE.md
  *                                                 # )
  *
  *
  * # listing all the files in a directory but not in subdirectories with '.php' file extension:
  *
  * $result = filesystem::search_files('src/lib', 'php', false); # Array
  *                                                              # (
  *                                                              #     [0] => include.php
  *                                                              # )
  *
  *
  *
  * @param string $path
  * @param string $extension
  * @param bool $recursively Set 'true' if you need to gather files from subdirectories
  *
  * @return array
  */
 public static function search_files($path, $extension = null, $recursively = true)
 {
     $file_list = null;
     if ($recursively === true) {
         $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
         foreach ($objects as $name => $object) {
             $file_list[] = $name;
         }
     } else {
         $file_list = scandir($path);
     }
     $result = array();
     if ($file_list) {
         foreach ($file_list as $file_path) {
             if (filesystem::is_dir($file_path)) {
                 continue;
                 # exclude directories
             }
             if ($extension === null) {
                 $result[] = $file_path;
                 continue;
             }
             if (filesystem::file_extension($file_path) == $extension) {
                 $result[] = $file_path;
             }
         }
     }
     return $result;
 }
开发者ID:ThisNameWasFree,项目名称:rude-univ,代码行数:85,代码来源:rude-filesystem.php


注:本文中的filesystem::file_extension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。