How can PHP be used to read and output .txt files with unknown filenames in a specific directory?

To read and output .txt files with unknown filenames in a specific directory using PHP, you can use the glob() function to retrieve an array of all .txt files in the directory. Then, you can loop through each file in the array and use file_get_contents() to read the contents of each file and echo it out.

$directory = "path/to/directory/";
$files = glob($directory . "*.txt");

foreach ($files as $file) {
    $content = file_get_contents($file);
    echo $content;
}