本文介绍了PHP GLOB一次不止一种模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码:
$matches = glob("$searchword*.txt", GLOB_BRACE) ;
这行得通,但我也有$ secondword,所以我读了
that works, but i also have $secondword, so i read How to define multiple patterns in php glob()
所以我尝试了
$matches = glob("{$searchword},{$secondword}*.txt", GLOB_BRACE) ;
$matches = glob("{$searchword,$secondword}*.txt", GLOB_BRACE) ;
$matches = glob("{$searchword*.txt},{$secondword*.txt}", GLOB_BRACE) ;
$matches = glob("$searchword*.txt", GLOB_BRACE) && ("$secondword*.txt", GLOB_BRACE);
$matches = (glob("$searchword*.txt", GLOB_BRACE) && ("$secondword*.txt", GLOB_BRACE));
导致语法无效
尝试做:通过glob列出与$ filename
相似的文件,是否可以对与$ filename相似的文件进行glob?
what im trying to do: list files via glob that are smilar to a $filenameis it possible to glob files that are similar to $filename?
引用:
推荐答案
我的目录中有多个 txt 文件。在这里,我将 glob
与 GLOB_BRACE
结合使用,它向我完美显示了预期的结果。
I've multiple txt files on my directory. Here I used glob
with GLOB_BRACE
and it perfectly showing the expected result to me.
$a = 'import_start_';
$b = '22_02_18_country_';
$m= glob("{{$a},{$b}}*.txt", GLOB_BRACE);
// OR //
// $m= glob({".$a.",".$b."}*.txt", GLOB_BRACE);
// OR //
print '<pre>';
print_r($m);
print '</pre>';
输出:
Array
(
[0] => import_start_date.txt
[1] => 22_02_18_country_list.txt
)
这篇关于PHP GLOB一次不止一种模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!