zoukankan      html  css  js  c++  java
  • PHP glob() 函数用法

    glob() 函数返回匹配指定模式的文件名或目录。

    该函数返回一个包含有匹配文件 / 目录的数组。如果出错返回 false。

    语法

    array glob ( string $pattern [, int $flags = 0 ] )

    <?php
    print_r(glob("*.txt"));
    ?>
    Array
    (
    [0] => target.txt
    [1] => source.txt
    [2] => test.txt
    [3] => test2.txt
    )
    You can fetch multiple file types like this:
    // get all php files AND txt files  
    $files = glob('*.{php,txt}', GLOB_BRACE);  
      
    print_r($files);  
    /* output looks like: 
    Array 
    ( 
        [0] => phptest.php 
        [1] => pi.php 
        [2] => post_output.php 
        [3] => test.php 
        [4] => log.txt 
        [5] => test.txt 
    ) 
    */  

    Note that the files can actually be returned with a path, depending on your query:

    $files = glob('../images/a*.jpg');  
      
    print_r($files);  
    /* output looks like: 
    Array 
    ( 
        [0] => ../images/apple.jpg 
        [1] => ../images/art.jpg 
    ) 
    */  

    If you want to get the full path to each file, you can just call the realpath() function on the returned values:

    $files = glob('../images/a*.jpg');  
      
    // applies the function to each array element  
    $files = array_map('realpath',$files);  
      
    print_r($files);  
    /* output looks like: 
    Array 
    ( 
        [0] => C:wampwwwimagesapple.jpg 
        [1] => C:wampwwwimagesart.jpg 
    ) 
    */  

    http://php.net/manual/en/function.glob.php

  • 相关阅读:
    Java Web三层架构设计深思
    编译C源码软件需要的工具
    Hibernate之表间关系
    CSS之颜色字体
    主流的微服务框架
    CSS布局思考
    Android创建新项目及开发
    Google工程师解析Android系统架构
    java多线程实用操作
    Spring IOC/DI/注解
  • 原文地址:https://www.cnblogs.com/youxin/p/3152860.html
Copyright © 2011-2022 走看看