remove ligne that contain <this particular chaine of cara

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rcmn
Forum Newbie
Posts: 21
Joined: Tue Jul 06, 2004 10:35 am

remove ligne that contain <this particular chaine of cara

Post by rcmn »

hi all i'm not a php dev,but i have to adapte a php code for my need.
i'm looking for a fonction that remove ,in a text file, a line when the line contain <chaine carac>.

Code: Select all

<?
	$filename = "mytextfile.txt";
	$config = file($filename);
	reset ($config);
	foreach ($config as $line)
		 {
		 if ( $line == "" ) next($config);          # Ignore blankline
		 elseif ( $line == "\n" ) next($config);    # Ignore newline
		 elseif ( strstr($line,"#")) next($config); # Ignore comments
		 else
			 {
			 $line = rtrim($line);  # Get rid of newline characters
			 $line = ltrim($line);  # Get rid of any leading spaces
			 echo $line."<br>";
			 }
		 }
?>
so ofter rtrim and ltrim i wich i could remove couple extra lignes
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

str_replace?
preg_match?
Post Reply