You are looking for the glob() function.
file_exists does not perform any search: it only lets you know if the fleck exists or not when you know its name.
And with PHP> = 5.3 you can use the new GlobIterator .
The following code is shown as an example with glob() :
$list = glob('temp*.php'); var_dump($list);
Gives me this result:
array 0 => string 'temp-2.php' (length=10) 1 => string 'temp.php' (length=8)
Although this one:
$list = glob('te*-*'); var_dump($list);
Yes, with two * ; -)
Give me:
array 0 => string 'temp-2.php' (length=10) 1 => string 'test-1.php' (length=10) 2 => string 'test-curl.php' (length=13) 3 => string 'test-phing-1' (length=12) 4 => string 'test-phpdoc' (length=11)
Pascal MARTIN Apr 30 '10 at 17:17 2010-04-30 17:17
source share