Re[2]: [PHP] Reading first line of data file then erase it

From: Date: Thu, 28 Dec 2000 10:07:56 +0000
Subject: Re[2]: [PHP] Reading first line of data file then erase it
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-32062@lists.php.net to get a copy of this message
Hello Philip, Thursday, December 28, 2000, 1:48:31 AM, you wrote: PO> Here's one way : PO> $filename = 'test.txt'; PO> // Open file as array PO> $pieces = file ($filename); PO> // Push away first piece into $firstline PO> $firstline = array_shift($pieces); PO> print $firstline; PO> // Open file and write it out, and now PO> // $firstline is gone. w+ is important. PO> $fd = fopen($filename,'w+'); PO> foreach ($pieces as $piece) { PO> fwrite($fd,$piece); PO> } Thanks for the reply I think I have already figured it out at lest it seems to work the way I want it to. //get the next avalable IP Address $fp=fopen ("ipdata","r")or die("unable to open file ($userdata)"); flock($fp, 2); $line = 0; while (!feof ($fp) && $line <1) { $buffer = fgets($fp, 4096); $line = $line + 1; } $ipaddress=$buffer; fclose($fp); //Loads all the data to a array and delets the 1st line $Lines = file('ipdata'); $LineToDelete =0; unset($Lines[$LineToDelete]); //Writes the data back to the file $file = fopen('ipdata', 'w'); flock($file, 2); fwrite($file, implode('', $Lines)); fclose($file); -- Best regards, Richard mailto:rkurth@pacifier.com

« previous php.general (#32062) next »