PDA

View Full Version : Opening multiple files in loop using php



mmeister3
07 Jun 2011, 03:23 PM
I started taking a web development class and im having trouble running a loop that opens multiple files.
The files are label as so:

movie_review0.txt
movie_review1.txt
movie_review2.txt
movie_review3.txt
movie_review4.txt

We have to write a loop not knowing how many files there are in the folder. Does anyone have any suggestions? I've tried using a while loop but I dont think I have the syntax correct. Thanks

resdog
08 Jun 2011, 08:01 AM
You could do something like this:


$directory = "/path/to/txtfiles/";
if (glob("$directory*.txt") != false)
{
$numfiles = count(glob("$directory*.txt"));
for ($i=0; $i < $numfiles; $i++) {
echo 'movie_review' . $i . '.txt<br />';
}
}