Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Replace/update array if it exists (PHP)

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

nigelwong

Established Member
Impact
3
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:
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?

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.

Thanks

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

PHP:
			//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
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

Parking: find your domains by pasting a list
You can now paste a list of domain names into the search box at the top of the Parking menu. Put one name on each line. Your domain list...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back