PHP带有正则表达式的.txt文件数组

时间:2022-09-01 23:13:26

I try to create an array of all .txt files in my directory with PHP. I do the following:

我尝试使用PHP在我的目录中创建所有.txt文件的数组。我做了以下事情:

$lel = glob('/.*\.txt/');

but it doesn't work - the array $lel is empty while there are .txt files in this directory. I checked it in online regexp tester and it seemed to work..

但它不起作用 - 数组$ lel为空,而此目录中有.txt文件。我在在线regexp测试仪上检查了它似乎工作..

1 个解决方案

#1


1  

glob() doesn't use preg expression syntax, it uses the simpler fpath syntax which is the same as on the command line. So you need to just check for just

glob()不使用preg表达式语法,它使用与命令行相同的更简单的fpath语法。所以你需要检查一下

$lel = glob('*.txt');

instead of

代替

$lel = glob('/.*\.txt/');

#1


1  

glob() doesn't use preg expression syntax, it uses the simpler fpath syntax which is the same as on the command line. So you need to just check for just

glob()不使用preg表达式语法,它使用与命令行相同的更简单的fpath语法。所以你需要检查一下

$lel = glob('*.txt');

instead of

代替

$lel = glob('/.*\.txt/');