Question: 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.

Answer: 
Take a look at the [glob()](http://php.net/manual/en/function.glob.php) 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.
In addition to [Yacoby's answer](https://stackoverflow.com/questions/2562298/php-how-to-search-a-file-using-wildcards/2562299#2562299), I would like to add that a new **[`GlobIterator`](http://fr2.php.net/globiterator)** class has been added to PHP >= 5.3.

It allows one to use wildcards, the same way as [`glob()`](http://fr2.php.net/manual/en/function.glob.php) does -- but, in additional :

* Tt implements the **[`Iterator`](http://fr2.php.net/manual/en/class.iterator.php)** interface
* You can have it work returning instance of the **[`SplFileInfo`](http://fr2.php.net/splfileinfo)** class

*So many useful things in the [**SPL (Standard PHP Library)**](http://fr.php.net/spl), and no-one ever thinking about them... I couldn't resist.*