Thanks george, But i want to read for multiple such files and i have many other keywords match which should be deleted.The array of keywords are ("[","TYP","P_MPP","I_MPP","V_MPP","T=","FIT","INTENSITAET"); and i aslo want to write back the reamaining lines after deleting into the same file but not in a different file. George Pitcher <george.pitcher@xxxxxxxxxxx> wrote: Hi, Do you just want to delete the lines containing '[' or 'TYP', or '[' AND 'TYP'? So your block would read: SUBSTRATNAME=S112 PIXEL=5 OPERATOR=Zi KOMMENTAR=dunkel INTENSITAET=1000.000000 DATUM=03.01.2005 UHRZEIT=11:22 MESSUNG=SWEEP_UI correct??? I would do the following: $filename="myfile.txt"; $target="myfile2.txt"; $handle = fopen ($filename, "r"); while (!feof ($handle)) { $buffer = fgets($handle, 8192); if (substr($buffer,0,1)!=='[' && substr($buffer,0,3)!=='TYP'){ $hf = fopen($target, 'a'); fwrite($hf, $buffer); fclose($hf); } } fclose ($handle); That should do the trick. George > -----Original Message----- > From: babu [mailto:garavindbabu@xxxxxxxxxxx] > Sent: 12 July 2005 12:13 am > To: php-general@xxxxxxxxxxxxx > Subject: how to delete lines in a txt file using php. > > > Hi i have a txt file like > [SUBSTRAT] > TYP=25x25_10 > SUBSTRATNAME=S112 > PIXEL=5 > OPERATOR=Zi > KOMMENTAR=dunkel > INTENSITAET=1000.000000 > [MESSUNG] > DATUM=03.01.2005 > UHRZEIT=11:22 > MESSUNG=SWEEP_UI > > i want to delete lines which start with '[' and 'TYP'. i have > multiple such files.i have used strstr method. i have written > code for it, but it results in deletion of complete data from > files. Can anyone check where the logic goes wrong. > here is my file. > > $del_lines=array("[","TYP","P_MPP","I_MPP","V_MPP","T=","FIT","INT > ENSITAET"); > $dir=getcwd(); > $handle = opendir($dir); > while (false !== ($file = readdir($handle))) { > if ((preg_match('/^2005\d{4}_\d{4}\.txt$/', > $file))||(preg_match('/^2005\d{4}_\d{4}\_01_01\.txt$/',$file))){ > $fc=file($file); > $f=fopen($file,"w"); > foreach($fc as $line){ > $bool=TRUE; > for($i=0;$i> if(!strstr($line,$del_lines[$i])){ > $bool=FALSE;} > break; > //fputs($f,$line); > } > //if($bool){fputs($f,$line);} > } > if($bool){fputs($f,$line);} > fclose($f); > } > } > closedir($handle); > ?> > > > > --------------------------------- > Yahoo! Messenger NEW - crystal clear PC to PCcalling worldwide > with voicemail --------------------------------- How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos. Get Yahoo! Photos