You can use PHP's `glob()` function to search for files with a specific file extension within a given directory. The `glob()` function accepts a wildcard pattern, which you can use to match file names in the directory.
The following is an example code that demonstrates how to use the `glob` function to retrieve all PHP files within a specified directory:
<?php
$dir = "/path/to/directory"; // 指定目录
$extension = "*.php"; // 指定后缀名
// 使用glob函数查询指定目录下的文件
foreach(glob($dir . '/' . $extension) as $file) {
echo $file . "\n";
}
?>This code first assigns the directory path and file extension to the variables $dir and $extension, respectively. Then, it uses the `glob` function to retrieve all files in the specified directory that match the given file extension, and employs a `foreach` loop to output the full path of each file.
You can modify the $dir and $extension variables as needed to query different directories and file types.