4

My question: is there a possibility to read multiple html files into a PHP file? I now use this code for reading the content from a file:

<?php
$file_handle = fopen("myfiles/file1.html", "r");
while (!feof($file_handle)) {
$line = fgets($file_handle);
echo $line;
}
fclose($file_handle);
?>

But this gives me only the content of file1.html

So i was wondering if it is possible to do something like this:

<?php
$file_handle = fopen("myfiles/*.html", "r");
while (!feof($file_handle)) {
$line = fgets($file_handle);
echo $line;
}
fclose($file_handle);
?>

The * above represents all .html files

Is there any way to do that?

tshepang
  • 12,111
  • 21
  • 91
  • 136
  • possible duplicate of [PHP list of specific files in a directory](http://stackoverflow.com/questions/3062154/php-list-of-specific-files-in-a-directory) – putvande Sep 01 '13 at 12:29

1 Answers1

4

Try this:

<?php
foreach (glob("myfiles/*.html") as $file) {
    $file_handle = fopen($file, "r");
    while (!feof($file_handle)) {
        $line = fgets($file_handle);
        echo $line;
    }
    fclose($file_handle);
}
?>
Josh
  • 2,835
  • 1
  • 21
  • 33