View Full Version : Problems with fopen

05-13-2004, 10:00 PM
It keeps reporting problems with line 5 in this code..


$file = fopen("num.txt", "r+")

fputs($file, "$file++");


echo ($file);


Whats the big problem?

05-13-2004, 10:30 PM
missing a semi colon on line 3

05-13-2004, 10:34 PM
Yeah.. finally spotted that heh...

But now I am getting weird results..

When I run it I get a print out of this..

Resource id #2

The original file has the number "100" in it & this is what I get by adding +1 to it????

All I am trying to do is increnement the files number by 1 & then get that new number in a variable.

05-13-2004, 11:01 PM
fopen links $file to a resourceid which is the pointer to the files internal position you would then need to use fread() to read the content using the $file resouceid and a loop

a better way to read the contents of the file in to a string is below

$content = file_get_contents($file);
$resourceid = fopen($file, "w");
fputs($resourceid, $content);
echo ($content);

05-13-2004, 11:08 PM
Ahh.. I see what you mean! :-)

Thanks for the code, works good! :)