hi i want to delete line from my csv file after echo or process this line can any one help???????????? thanks in advance!!!!!

here is my code

$fp = fopen('surInput.csv','r') or die("can't open file");
while($csv_line = fgetcsv($fp,1024)) {
    for ($col = 0, $j = count($csv_line); $col < $j; $col++) {
        echo $csv_line[$col];
		echo "<br>";
		//now after show or processed i want to delete this line  ($csv_line)
		
    }
}
fclose($fp) or die("can't close file");

Recommended Answers

All 2 Replies

There might be another way but the classic way of handling a sequential file is to write a new copy (and then replace the old copy with the new one at the end). A CSV sequential file isn't a database and it isn't meant to handle random reads and writes. As a variation on this, you could read your whole file into an array (if it isn't too big), make all of your changes then write the whole thing back to the original file (wiping out the previous contents).

my csv file is so big it has more than 1 Lac lines.
so i cant offered to delete each line in end of program,,,,i want delete each line after display or process
(display line,then delete this line=>display line,then delete this line..............)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.