M David
M David

Reputation: 127

glob only pulling array if I use wildcard

I'm trying to use glob() to find images in my folder that match a pattern. There are too many images to manually search through, so glob() seems like a good approach.

I don't seem to be able to get glob to work, however.

I have 5 images with the following patter: diamond_z_classic_397-106 but when I use glob as such:

print_r(glob("diamond_z_classic_397-106.*")); then this is what is returned array() . When I do this: pring_r(glob("*.*")); then it pulls everything from the directory included the 5 matches.

I've scanned SO as well as http://php.net/manual/en/function.glob.php and http://www.w3schools.com/php/func_filesystem_glob.asp to figure out what I'm missing.

What could be causing this, or what am I missing.

Also, is it possible to use a variable like this: glob("$pattern.*"); ?

Thanks

Update Here are the 5 exact names that should match the pattern: diamond_z_classic_397-106-100-80-100-c-rd-255-255-255.jpg

diamond_z_classic_397-106-100-80-100-c.jpg

diamond_z_classic_397-106-120-90-100-c.jpg

diamond_z_classic_397-106-300-300-100-wm-center_middle-0-ColorCountryAussies-255-255-255-35.jpg

diamond_z_classic_397-106-800-800-100-wm-center_middle-0-ColorCountryAussies-255-255-255-35.jpg

Upvotes: 1

Views: 87

Answers (2)

Michael Bellomo
Michael Bellomo

Reputation: 1

You probably have truncated your filename with "." and its taking it literally. Try something like

print_r(glob("diamond_z_classic_397-106*"));

Also yes, you can define a string beforehand and pass it as an argument.

$pattern = "xyz*"
print_r(glob($pattern));

Upvotes: 0

user3942918
user3942918

Reputation: 26375

Remove the . from your pattern, i.e. glob("diamond_z_classic_397-106*").

With glob * alone matches zero or more of any character. You're attempting to match a literal . that doesn't exist at that place in your file names.

Upvotes: 2

Related Questions