Forum Moderators: coopster

Message Too Old, No Replies

making a text file value into a variable

how do i do it?

         

laura2k

4:16 pm on Mar 18, 2004 (gmt 0)



Hi,

I have a text file called data.txt that has one line of data with a number in it e.g. 500, basically i need a code that will read the first line of data.txt and store it as a variable e.g. $data = data and + 1 to the actual data.txt file. so this way the data.txt becomes 501 but the variable for the user is 500.

Its just like a counter.

Thanx in advanced

Birdman

4:26 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are a few ways to do it. Here's one:

$file = "/path/to/file.text";
$data = file_get_contents [php.net]($file);
$data2 = $data + 1;
$handle = fopen [php.net]($file, "w");
fwrite [php.net]($handle, $data2);
fclose($handle);

You will have to chmod the text file to allow it to be written to.

laura2k

4:41 pm on Mar 18, 2004 (gmt 0)



thanx, it works a treat