Sign in to follow this  
CGtech

[web] PHP - reading the file

Recommended Posts

CGtech    123
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
Chman_a11w    128
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
Pro-XeX    130
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
botman2    211
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this