Re: how to delete some lines in a file

From: Date: Thu, 13 Jul 2000 18:58:04 +0000
Subject: Re: how to delete some lines in a file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-6533@lists.php.net to get a copy of this message
Make sure you end the "new" with a carriage return, like "new\n". That will put them all on separate lines. One way you can delete lines is this: $array = file("file.txt"); $deleteline = 8; // what line to delete $fp = fopen("file2.txt","w"); for($i=0;$i<count($array);$i++) { if($i!=$deleteline) fputs($fp,"$array[$i]\n"); } fclose($fp); That code is untested, but should give you and idea on how to proceed. Hans On Thu, 13 Jul 2000, xinkun wang wrote: > if I want to delete some lines in a file, I must fopen it and save it in an > array, but I can't delete elements in the array due to lacking of such > function, any ideas? > if I make it like for ($i=0;i<10;i++) > $array[$i]="new"; > and write it to the file, the result is file wirte "new"s in one line, not > in 10 line saperately. I don't know why. > > > ________________________________________________________________________ > Get Your Private, Free E-mail from MSN Hotmail at > http://www.hotmail.com > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > Hans Anderson ~ me@hansanderson.com PO Box 426, Missoula, MT 59806 | PHP, Search Engines, SQL (800)397-9116 / (406)549-6524 | Databases, Flash Multimedia, http://www.hansanderson.com | Killer Audio Production, http://www.goofiness.com | Minty Fresh Breath.

« previous php.general (#6533) next »