file() and echo

Having problem displaying file read by file() function
Here is my code.

[php]<?php
$file = “log.txt”;
$lines = file($file);
for($i=0;$i<count($lines);$i++);
{
echo $lines[$i];
}
echo count($lines);
?>[/php]

My log.txt

user1 logged user2 logged user4 logged user6 logged user3 logged user9 logged

The page is just a .php page, and my expectation was to see printed on the screen the same as the log.txt.
But all it displays is 5, or 20 , or 100, or however may logged users there are in the log.txt.

I am pretty noob so Im guessing this could be a fundamental error.

That id not the only thing I’ve tried I’ve trie a few other things such as this.
[php]<?php
$file = “log.txt”;
$lines = file($file);
for($i=0;$i<count($lines);$i++);
{
echo $lines[$i] . “
\n”; // and . “\n” and . “\r” and . “\r\n” etc
}
echo count($lines);
?>[/php]

I would really appreciate any pointers.

I am not really sure what is the problem, as I can not see the content of your log file. Your PHP code is fine. I would do even shorter:
[php]<?php
echo implode(’
’,file(‘log.txt’));
?>[/php]

Well it goes without saying I’m not sure what the problem is either.

So Its a great thing that your example does work as I expected my own to.

Thank you very gladly for your time and help.

Sponsor our Newsletter | Privacy Policy | Terms of Service