cyphix
05-13-2004, 10:00 PM
It keeps reporting problems with line 5 in this code..
<?php
$file = fopen("num.txt", "r+")
fputs($file, "$file++");
fclose($file);
echo ($file);
?>
Whats the big problem?
sidney
05-13-2004, 10:30 PM
missing a semi colon on line 3
cyphix
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.
sidney
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
<?php
$file="num.txt";
$content = file_get_contents($file);
$content++;
$resourceid = fopen($file, "w");
fputs($resourceid, $content);
fclose($resourceid);
echo ($content);
cyphix
05-13-2004, 11:08 PM
Ahh.. I see what you mean! :-)
Thanks for the code, works good! :)