NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Replace/update array if it exists (PHP)

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 07-21-2006, 12:41 AM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Nov 2005
Posts: 66
nigelwong is an unknown quantity at this point
 



Replace/update array if it exists (PHP) [FIXED]


Hi,

I currently have a php script which writes to a text file once a file is downloaded:
PHP Code:
fwrite($handle_download"$file|$ip|$time|$day|$month|$year\n"); 
However i want it so that it UPDATES instead of writing it down again (or delete the old entry). Is there a way that if $file is going to be written to the text file again, that it look for all instances for $file and delete them? How would i do that?
????: NamePros.com http://www.namepros.com/programming/219298-replace-update-array-if-exists-php.html

I am doing this because i want to do an 'inactivity' script where it finds all instances in the script where $time exceeds a certain limit, and if it does it will delete it (therefore if there are older instances of the file, it will delete it even though it may still be active)

If anyone can help me out, it will be greatly appreciated.
????: NamePros.com http://www.namepros.com/showthread.php?t=219298

Thanks

I have tried this in my script, but it doesnt work.

PHP Code:
            //Delete Previous Download Entry if it Exists
            
$entry=file("$file_download");
            
$ent=fopen("$file_download""w");
            foreach(
$entry as $line2)
            {
              
$thisline explode('|'$line2);
              if (
$thisline[0] == $file)
                
fputs($ent,$line2);
              else
            unset(
$thisline);
            }
            
fclose($ent); 
EDIT: I got it working, i accidently swapped the "unset($thisline)" and the other function around =P
__________________
Free AJAX Proxy: http://www.ctrlaltproxy.com
Useful DHTML/AJAX tutorials: http://www.dhtmlsite.com
Last edited by nigelwong; 07-21-2006 at 03:26 AM.
nigelwong is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 08:16 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger