当前位置:网站首页>PHP使用glob()查找文件
PHP使用glob()查找文件
2022-08-08 20:24:00 【李斌的BLOG】
大部分PHP函数的函数名从字面上都可以理解其用途,但是当你看到 glob() 的时候,你也许并不知道这是用来做什么的,其实glob()和scandir() 一样,可以用来查找文件,请看下面的用法:
// 取得所有的后缀为PHP的文件
$files =glob(‘*.php');
print_r($files);
/* 输出:
Array
(
[0] => phptest.php
[1] => pi.php
[2] => post_output.php
[3] => test.php
)
*/
你还可以查找多种后缀名:
// 取PHP文件和TXT文件
$files =glob(‘*.{php,txt}', GLOB_BRACE);
print_r($files);
/* 输出:
Array
(
[0] => phptest.php
[1] => pi.php
[2] => post_output.php
[3] => test.php
[4] => log.txt
[5] => test.txt
13.
)
*/
你还可以加上路径:
$files =glob(‘../images/a*.jpg');
print_r($files);
/* 输出:
Array
(
[0] => ../images/apple.jpg
[1] => ../images/art.jpg
)
*/
如果你想得到绝对路径,你可以调用 realpath() 函数:
$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:\wamp\www\images\apple.jpg
[1] => C:\wamp\www\images\art.jpg
)
*/
边栏推荐
猜你喜欢
What are the latest developments in the handling of false information?KDD2022 "Fighting Misinformation and Responding to Media Bias" tutorial, 161 pages ppt
Ansible自动化运维工具(一)安装及模块
wps表格怎么设置公式自动计算?wps表格设置公式自动计算的方法
Word清除格式在哪里?Word清除格式使用方法
SushiSwap「SUSHI」下降了 93%,但还没有完全消失
C语言初阶-指针
What are the role of document management system for companies?
JMeter测试接口并发场景
【翻译】用Argo CD揭开企业规模的持续交付的秘密成分
曲面着色器初试--地面轨迹模拟(部分细节不完善)
随机推荐
方舟综合指令代码大全系统综合
idea 引入包报错:Unable to provision, see the following errors
Gartner:2022年全球半导体收入增长预计将放缓至7%,远低于2021年26.3%
梅科尔工作室OpenHarmony设备开发培训笔记-第一章学习笔记
微服务负载均衡器Ribbon
投资基金定投安全吗
C语言初阶-指针
OpenEuler's Ways to Improve Resource Utilization 02: Effects under Typical Applications
场外基金开户在手机办理安全吗?
Yarn 总结(未完待续)
同花顺买股票软件正规吗?安全吗?
黑猫带你学Makefile第8篇:uboot/kernel中的makefile基本语法与流程
制作实例分割数据集
黑猫带你学Makefile第10篇:如何将未被编译的代码/自己写的驱动编译进uboot
电脑win键没有反应(最全方案)
How can recommender systems be trusted?A review of the latest "Trusted Recommender System" from Rutgers University, a 43-page pdf explaining the composition and technology of trusted RS
黑猫带你学Makefile第3篇:Makefile基本语法
测试面试题锦集
What are the latest developments in the handling of false information?KDD2022 "Fighting Misinformation and Responding to Media Bias" tutorial, 161 pages ppt
小白如何购买基金产品?