Maciek
Maciek

Reputation: 1982

php glob pattern ending may or may not have

I am trying to find files that start with "image_1" and may or may not end with "_main"

$glob=glob("/image_1{_main}.jpeg");

So it would match

image_1_main

image_1

but not image_11. What would be the pattern here? Do I use {_main}?

Upvotes: 1

Views: 155

Answers (1)

Maciek
Maciek

Reputation: 1982

I forgot to add the flag to globe to make "{}" work. You need "GLOB_BRACE" in glob function;

$glob=glob("/image_1{,_main}.jpeg",GLOB_BRACE);

Upvotes: 2

Related Questions