PHP file_exists and wildcard

You’re looking for the glob() function.

file_exists doesn’t do any kind of search : it only allows one to know whether a file exists or not, when knowing its name.

And, with PHP >= 5.3, you could use the new GlobIterator.

As an example with `glob()`, the following portion of code :

$list = glob('temp*.php');
var_dump($list);

Gives me this output :

array
  0 => string 'temp-2.php' (length=10)
  1 => string 'temp.php' (length=8)

While this one :

$list = glob('te*-*');
var_dump($list);

Yes, with two * 😉

Will 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)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)