Skip to main content
GameDev.net gamedev.net
🔒 Locked 🤖 Godot

[web] PHP - reading the file

Started by CGtech Jul 7, 2004 at 12:51 PM 3 replies 1.5k views
Original Post
CGtech
CGtech
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).
Perfection is a powerful message
Chman_a11w
Chman_a11w
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.
Caramelo
Caramelo
Maybe you could use something like this

// read the file contents into array - $uo
$uo = file ('fileurl');
for( $i=0; $i echo $uo[$i] . NL;
.
botman2
botman2
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");
CGtech
CGtech
Thanks everybody! I attempted to reply before but the was an error and I lost the message.
Perfection is a powerful message

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.