PHP:如何使用通配符搜索文件 [英] PHP: How to search a file using wildcards

查看:301
本文介绍了PHP:如何使用通配符搜索文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用PHP读取文件,但是我只知道文件名的结尾,因此我需要使用通配符:* filename.wav将文件放在给定目录中,然后将其返回到浏览器. 有功能吗?还是我需要获取目录中的所有文件,然后一个一个地搜索?

I need to read a file in PHP, but I only know the end of the filename, so I need to serch the file in a given directory using wildcards: *filename.wav and then return it to the browser. Is there a function to do that? or I need to get all the files in the directory and then search one by one?

感谢所有评论和帮助.

推荐答案

看看 glob()函数

例如,如果要获取子目录dir

For example if you wanted to get every file matching *abc.xyz in the subdirectory dir

$matches = glob('./dir/*abc.xyz');

请注意,glob不是递归的,只会搜索一个目录,而不是所有子目录.

Note that glob isn't recursive and will only search a single directory and not all sub directories.

这篇关于PHP:如何使用通配符搜索文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆