You could do something like this:
PHP Code:
$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 />';
}
}
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
You could do something like this:
PHP Code:
$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 />';
}
}