Re: Reading and writing to a text file

From: Date: Mon, 06 Nov 2000 06:16:20 +0000
Subject: Re: Reading and writing to a text file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-23848@lists.php.net to get a copy of this message
On Mon, 06 Nov 2000 05:27:50 GMT, Ivan Quintero (rodryquintero@hotmail.com) wrote: >I have problems writing a two digit number to a text file. Here is >the code: > >-- Begin Code ---- >if (!$archivo = fopen("contador_banner.txt", "r+")) >{ > echo "Error"; > exit; >} > >if (!$texto = fread ($archivo, 2)) >{ > echo "Error"; > exit; >} > >$texto = $texto + 1; I'm just guessing, but I'd say that this expression would evaluate to 1. It looks like you're trying todo c-style pointer arithmetic , but this isn't realIy something I've seen in php A better way to do it would be to read the whole file, put it in a string, parse the number, and when you're done, write the whole thing back to the file. >rewind ($archivo); > >fputs ($archivo, $texto); >fclose ($archivo); > >---- End of Code ---- > >I am writing a very rudimentary banner rotation program. This code >snippet >accomplishes one task: write a number that indicates the next banner >to be >displayed. This number is accumulated each time a banner is >displayed. > >Since the code above appends the number at the end of the file, I >have >problems when it comes to calculating two digit numbers. Among other >things. > >Thanks in advance. > >_____________________________________________________________________ >____ >Get Your Private, Free E-mail from MSN Hotmail at >http://www.hotmail.com. > >Share information about yourself, create your own public profile at >http://profiles.msn.com. > > >-- >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

« previous php.general (#23848) next »