Hey there,
I am currently working on a PHP project where I need to use the glob function. I've been reading the PHP documentation about it, but there's one thing I can't figure out. Is it possible to use a variable instead of a string as the pattern parameter in the glob function?
Here's what I'm trying to do. I have a variable called $fileExtension which holds the file extension I'm interested in. Let's say it's "pdf". I want to use this variable as the pattern parameter in the glob function, like this: glob("path/to/files/*.$fileExtension").
But when I try this, it doesn't seem to work. I only get an empty array as a result. I've also tried using concatenation, like glob("path/to/files/*." . $fileExtension), but that didn't work either.
Am I doing something wrong? Is it not possible to use a variable inside the glob function? If not, is there any workaround or alternative approach I can use to achieve the same result?
I appreciate any help or insights on this matter.
Thanks!

Hey,
Yes, it is definitely possible to use a variable in the glob function in PHP. I've been using it in my projects and it works without any issues. I see that you're using concatenation to include the variable within the pattern, which is the correct approach.
In your case, the issue might be with the value of the $fileExtension variable. Make sure that it is set correctly before calling the glob function. You can also double-check the path to your files and ensure that it is accurate.
Another thing to consider is that the glob function follows the rules of your operating system for file matching. So, if you're working on a Windows machine, you need to use a backslash (\) as the directory separator in the pattern. For example: glob("path\to\files\*." . $fileExtension).
If none of these suggestions solve your problem, it would be helpful to see more of your code. Maybe there's another issue that we can pinpoint.