RE: [PHP] how to delete lines in a txt file using php.

2005-07-12 Thread babu
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 <[EMAIL PROTECTED]> 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.00
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:[EMAIL PROTECTED]
> Sent: 12 July 2005 12:13 am
> To: php-general@lists.php.net
> Subject: [PHP] 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.00
> [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

Re: [PHP] how to delete lines in a txt file using php.

2005-07-11 Thread Richard Lynch
On Mon, July 11, 2005 4:13 pm, babu said:
>  $f=fopen($file,"w");

http://php.net/fopen

"w" will open the file for WRITING, a fresh, new, EMPTY file.

You want "r+" or "a+" or "w+" or something similar.

-- 
Like Music?
http://l-i-e.com/artists.htm



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] how to delete lines in a txt file using php.

2005-07-11 Thread babu
Hi i have a txt file like 
[SUBSTRAT]
TYP=25x25_10
SUBSTRATNAME=S112
PIXEL=5
OPERATOR=Zi
KOMMENTAR=dunkel
INTENSITAET=1000.00
[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.

 


-
Yahoo! Messenger NEW - crystal clear PC to PCcalling worldwide with voicemail