General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 15th, 2003, 05:20 AM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to steve55 Send a message via Yahoo to steve55
Deleting code from a text file

I have a form that updates a text file (ads.txt) with an image and url, to create a dynamic banner advertising page. The form references a script which is shown below.

I can add items to the text file, but don't know how to DELETE them. Please could someone show me how to amend the script in order for it to delete a line from the text file, rather than add it.

Thank you.

---------------------------------------------------------
THE CODE
---------------------------------------------------------

<?php

$adsfile = "ads.txt"; //the ads file

$page = $adsfile;
$filename = $adsfile;
$fd = fopen( $filename, "r" );
$current = fread( $fd, filesize( $filename ) );
fclose( $fd );

$ad = "<a href='$url' target='new'><IMG SRC='$adurl' border=0></a>";
$ad .= "<BR><BR>";
$ad .= "
";

if (file_exists("$page")){
$cartFile = fopen("$page","a[b]");
fputs($cartFile,$ad);
fclose($cartFile);
}
else
{
$cartFile = fopen("$page","a[b]");
fputs($cartFile,$ad);
fclose($cartFile);
}

php?>

<?php

//done

php?>

---------------------------------------------------

Reply With Quote
  #2  
Old May 16th, 2003, 06:09 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
one simple solution is to use str_replace to find any instances of a line and replace it with nothing, or you could use regular expressions to do the same thing.

however it would be better to use a database then a text file

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Deleting code from a text file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway