Home >Backend Development >PHP Tutorial >How to List Specific Files with a Specific Extension in a Directory Using PHP?
List Specific Files in a Directory with PHP
The code you provided lists all files within a given directory. However, you are seeking a solution to exclusively list files that end with the ".xml" or ".XML" extension.
To achieve this with PHP, there is a built-in function called glob() that is designed for this specific purpose. Here's an example of how to use it:
$files = glob('/path/to/dir/*.xml');
In this example, glob() will search for files within the /path/to/dir directory that end with the ".xml" extension. The result will be an array containing the matching file names.
The above is the detailed content of How to List Specific Files with a Specific Extension in a Directory Using PHP?. For more information, please follow other related articles on the PHP Chinese website!