Re: Is This Code OK?

From: Date: Sat, 21 Oct 2000 09:35:25 +0000
Subject: Re: Is This Code OK?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-21537@lists.php.net to get a copy of this message
This is how I would do it (I'm a unix geek so this won't work for you NT people). <? $file = '/tmp/data.txt'; $fp = fopen($file,'r'); $value = fread($fp,filesize($file)); fclose($fp); $new_value = ($value + 1); echo "\$hits = $new_value" > $file; ?> Double check my syntax on the echo "\$hits = $new_value" > $file; --Joe On Sat, Oct 21, 2000 at 12:55:03PM +0500, iGuru wrote: > Can anyone please check if the below mentioned code is correct or can be > reduced further. I am trying to make a simple page counter with this code. > Note that the data.txt file only contains the number '1' at startup. > > Can you please check if the below mentioned code is correct or can be > reduced further. I am trying to make a simple page counter with this code. > Note that the data.txt file only contains the number '1' at startup. > > <?php > $file_loc = "data.txt"; > > $oldfile = fopen($file_loc,"r"); > $file_contents = fread($oldfile,filesize($file_loc)); > $oldval = $file_contents; > fclose($oldfile); > > $newfile = fopen($file_loc, "w+"); > echo $old; > $old = fread($newfile, $newfile); > $newval=$oldval+1; > fwrite($newfile, "$newval"); > fclose($newfile); > echo $newval; > ?> > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net /*****************************\ * Joe Stump * * www.Care2.com * * Office: 650.328.0198 * * Extension: 122 * \*****************************/ http://www.miester.org/Joe/Stump/Joe_Stump_resume.html -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GB/E/IT d- s++:++ a? C++++ UL++$ P+ L+++$ E----! W+++$ N+@ o? K? w---! O-@ M+@ V-! P(++) PE(+) Y+@ PGP+++@ t+@ 5? R-! tv@ b+ DI++@ D(++++) G++@ e+@ h@ r+! z(+++++**)! ------END GEEK CODE BLOCK------

« previous php.general (#21537) next »