PHP reading files in a loop

Im having problems reading text files in a php loop. This is an easier example of my code and I know I should check to see it the file exists that is in my longer version but no matter what I do this won/t read my text files. The PHP warnings say that the text files are empty but they aren't. The PHP is writting the <br /> tho.

for ($i=1; $i<=5; $i++)
{
   $myFile = "$i.txt";
   $readfile = file_get_contents($myfile);
   echo "$readfile <br />";
}

Answers


Your passing $myfile in file_get_contents but it's called $myFile above (case sensitive)


Variables are case-sensitive.

for ($i = 1; $i <= 5; $i++) {
    $myFile = "$i.txt";
    $readfile = file_get_contents($myFile);
    echo "$readfile<br />";
}

If you simplify your code, there are less chances to make an error:

for ($i=1; $i<=5; $i++)
{
   readfile("$i.txt");
   echo "<br />";
}

Need Your Help

Unable to isolate onbeforeunload() scenarios in PHP

php jquery

I have a PHP application that stored the session ID of a user upon login in a MYSQL table, which is removed when the user logs out and their session is destroyed through the logout process. the Use...

iOS UIButton Touch-Up-Inside weird behavior

ios objective-c uitableview uibutton touch-up-inside

My iOS application contains a tableView and has a today widget extension wich also contains a tableView.