You can use the `glob` function in PHP to match file names within a specified directory, and then use the `unlink` function to delete those files.
The specific operating steps are as follows:
- Use the `glob` function to match file names within a specified directory and store the results in an array; the code is as follows:
$files = glob('/path/to/dir/*.txt');Here, `/path/to/dir` refers to the directory to be operated on, and `*.txt` refers to the file name pattern to match – in this case, all files with the `.txt` extension.
Iterate over the file array and call the `unlink` function on each file to delete it; the code is as follows:
foreach ($files as $file) { unlink($file); }The complete code is as follows:
$files = glob('/path/to/dir/*.txt'); foreach ($files as $file) { unlink($file); }
The above code will delete all files with the.txt extension in the specified directory.