re:Incremnting a number in a file
| From: | Joseph H Blythe | Date: | Fri, 04 Feb 2000 05:54:19 +0000 |
| Subject: | re:Incremnting a number in a file | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-9783@lists.php.net to get a copy of this message | ||
Hi all,
I am having a problem trying to open, read then write an incremented
number into a file.
here is the simplistic code I have so far:
The file txndata has already been created and is in /tmp it is readable
and writeable by user/group nobody:nobody and others, it has the value
of 0 inside of it.
<?php
$tdata = "/tmp/txndata";
$fo = fopen("$tdata","w+");
$fr = fread($fo, filesize($tdata));
$fi = $fr++;
$fw = fwrite($fo,$fi);
fclose($fo);
echo "Number = $fi";
?>
It returns
Number =
It seems to wipe out the 0 in the file, Is this because $fr does not
actually return the contents of the file it always seems to equal 1 ?
If that is true then how do I read the contents of a file into a string?
This has me stumped I have also tried this various ways I must be
missing something or have the totally wrong idea how this works.
Any help much appreciated,
Joseph H Blythe
Boldweb Internet / Binary Logic
257 Churchill Road Prospect,
Adelaide South Australia 5082
PH: 08 8342 0022
FAX: 08 8342 0155
mailto:webdevel@binarylogic.com.au