问题
code:
$matches = glob("$searchword*.txt", GLOB_BRACE) ;
that works, but i also have $secondword, so i read How to define multiple patterns in php glob()
so i tried
$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));
results in invalid syntax
what im trying to do: list files via glob that are smilar to a $filename is it possible to glob files that are similar to $filename?
references: https://www.cowburn.info/2010/04/30/glob-patterns/
回答1:
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>';
Output:
Array
(
[0] => import_start_date.txt
[1] => 22_02_18_country_list.txt
)
来源:https://stackoverflow.com/questions/49314061/php-glob-more-than-one-pattern-at-a-time