I need to read a file in PHP, but I only know the end of the filename, so I need to serch the file in a given directory using wildcards: *filename.wav and then return it to the browser. Is there a function to do that? or I need to get all the files in the directory and then search one by one?
Thanks for all the comments and help.
The asterisk ( * ) Use it when searching for documents or files for which you have only partial names. For most web search engines, wildcards increase the number of your search results.
You can use your own wildcards to limit search results. You can use a question mark (?) as a wildcard for a single character and an asterisk (*) as a wildcard for any number of characters. For example, *. pdf would return only files with the PDF extension.
Wildcards take the place of one or more characters in a search term. A question mark (?) is used for single character searching. An asterisk (*) is used for multiple character searching. Wildcards are used to search for alternate spellings and variations on a root word.
Take a look at the glob() function
For example if you wanted to get every file matching *abc.xyz
in the subdirectory dir
$matches = glob('./dir/*abc.xyz');
Note that glob isn't recursive and will only search a single directory and not all sub directories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With