0

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");

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by hassan12345
0

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).

0

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..............)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.