How can one efficiently read and output specific lines from multiple text files in a directory using PHP?

To efficiently read and output specific lines from multiple text files in a directory using PHP, you can use a combination of functions like opendir(), file(), and fgets(). By looping through each file in the directory, you can read the contents line by line and output the specific lines you need.

<?php
$directory = "path/to/directory";
$files = scandir($directory);

foreach($files as $file){
    if(is_file($directory . "/" . $file)){
        $lines = file($directory . "/" . $file);
        // Output specific lines from $lines array
        echo $lines[0]; // Output the first line
        echo $lines[2]; // Output the third line
    }
}
?>