|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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?> --------------------------------------------------- |
|
#2
|
|||
|
|||
|
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 ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Deleting code from a text file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|