Important alert: (current site time 7/15/2013 10:24:19 AM EDT)
 

VB icon

a super simple way to remove a line from a text file

Email
Submitted on: 7/17/2001 3:09:37 PM
By: Digital  
Level: Intermediate
User Rating: By 3 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 15043
author picture
(About the author)
 
     Have you ever wanted just a simple function to remove a line from a text file? All that seems to be avaliable is class this class that.. well no more! This function takes a string, and if it finds that string on a line, it removes the line.. Its a useful starter for something more involved.. or just as is...
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :a super simple way to remove a line from a text file
//**************************************
Reference www.de-net.org with any use of this function!
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: a super simple way to remove a line from a text file
// Description:Have you ever wanted just a simple function to remove a line from a text file? All that seems to be avaliable is class this class that.. well no more! This function takes a string, and if it finds that string on a line, it removes the line.. Its a useful starter for something more involved.. or just as is...
// By: Digital
//
// Inputs:$victim_file - the file we parse
$taboo_string - the string that means the whole line goes away
//
// Returns:nothing
//
// Assumes:you need to understand that file() returns an array..
//
// Side Effects:internal bleeding, unexpected pregnancy in men
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=380&lngWId=8//for details.//**************************************

function TerrorizeFileSelectively($victim_file, $taboo_string)
{
$i = 0;
$file1 = file($victim_file);
$fp = fopen($victim_file, "w");
while ($i <= sizeof($file1))
{
 if (strstr($file1[$i], $taboo_string))
 {
 $file1[$i] = "";
 }
 fwrite($fp, $file1[$i]);
 ++$i;
}
fclose($fp);
}


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
4/19/2002 3:55:15 AMtuk

u're da man
(If this comment was disrespectful, please report it.)

 
6/1/2004 4:36:43 AM

why when I remove the string 192.168.10.10, but the 192.168.10.101 also remove too? please help...
(If this comment was disrespectful, please report it.)

 
8/10/2007 8:33:37 AMZeuC

192.168.10.10
192.168.10.101
this script uses strstr if you take a look 192.168.10.10 is part of 192.168.10.101, so I suggest you use strcmp
yes I know this post is wayyyyyy too old but still :P I felt I just had to post xD
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.