• Advertisement
Sign in to follow this  

[web] PHP - reading the file

This topic is 4974 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I used to use PHP, but stopped for multiple reasons. Now I am re-teaching it to myself. Right now to test my memory I pulled out an old project from the "to program" area (everything, but the code it done). The program is a P2P chat client to be used to communicate with my game development team. The one part that won't work is reading from the files. I don't quite remember how to do this. The code that I used is: while (!feof($f)) { $x=fgetc($f); $uo = $uo + $x; } All that I am trying to do is get the content of the file stored as a variable($uo).

Share this post


Link to post
Share on other sites
Advertisement
Quote:
while (!feof($f))
{
$x=fgetc($f);
$uo = $uo + $x;
}


You should use $uo = $uo.$x; instead of $uo = $uo + $x; :)

Edit: there's a faster way to read file content. Take a look at Clicky.

Share this post


Link to post
Share on other sites
Maybe you could use something like this

// read the file contents into array - $uo
$uo = file ('fileurl');
for( $i=0; $i<count($uo); $i++ )
echo $uo[$i] . NL;

Share this post


Link to post
Share on other sites
Or just:

$file = file("fileURL");

foreach ($file as $line) {
$uo = $uo.$line;
}

Edit: But reading that above URL, file_get_contents() is easier still.

$uo = file_get_contents("fileURL");

Share this post


Link to post
Share on other sites
Thanks everybody! I attempted to reply before but the was an error and I lost the message.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement