hello,
i have a file that needs a value to be incremented.
the file looks like this
1|56
2|34
the first coloum is the line number that is written in the file the second coloum is how many times that line has been accessed.
So if the user goes to this page .. page.php?id=2, line two / 2nd coloum will be incremented to 35.
How can i do this in php so that the entire file will be re-written and the number will be incremented?
here is what I have, but not sure if I should go about this way..
$file_tmp = "$file" . ".tmp";
copy("$file", "$file_tmp");
// this creates a duplicate of $file called
// $file_tmp.
$file=fopen($file_tmp,"w");
flock($file, 2);
$info = file("$file");
for ($i=0; $i<count($info); $i++) {
$di = explode("|", $info[$i]);
fputs($file, "$di[0]|$di[1]\n");
}
flock($file, 3);
fclose($file);
unlink($file);
rename("$file_tmp", "$file");
basically all I have right now, is that the file is split into arrays and re-written into the file. Then the original file is removed and the temp file is renamed to the original file.
All I need is for the number to be incremented and re-written with the incremented number.
What I have so far should shorten the time for you to do this. Thanks for all your help!