Page 1 of 1

remove ligne that contain <this particular chaine of cara

Posted: Tue Jul 06, 2004 10:35 am
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

Posted: Tue Jul 06, 2004 10:47 am
by lostboy
str_replace?
preg_match?