Re: adding numbers to a file
| From: | Rasmus Lerdorf | Date: | Mon, 22 Apr 2002 15:50:24 +0000 |
| Subject: | Re: adding numbers to a file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-94031@lists.php.net to get a copy of this message | ||
$lines = file('filename');
foreach($lines as line) {
list($var,$val) = explode('=>',$line);
if(trim($var)=="'total'") $val = trim($val);
}
$val = $new_value;
$fp = fopen('filename','w');
fputs($fp,"{\n'total' => $new_value\n}");
fclose($fp);
-Rasmus
On Mon, 22 Apr 2002, Craig Westerman wrote:
> I have a simple count file named count_db that contains ONLY the following:
>
> {
> 'total' => 39540000
> }
>
> How do I open file, find numbers in the file, add $newnumbers to existing
> numbers. Then write these new numbers over the original numbers and close
> the file. I'm just needing to do this once a day to correct a poor count.
>
> Thanks
>
> Craig ><>
> westerman@chanuteks.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>