How can glob() be used to filter specific files for renaming in PHP?

To filter specific files for renaming using glob() in PHP, you can use the pattern matching capabilities of the function to only select the files that meet your criteria. By providing a specific pattern that matches the files you want to rename, you can easily iterate over the list of files returned by glob() and rename them accordingly.

// Specify the pattern to match specific files for renaming
$files = glob('path/to/files/*.txt');

foreach ($files as $file) {
    // Rename the file as needed
    $newName = str_replace('.txt', '_new.txt', $file);
    rename($file, $newName);
}