Answer the question
In order to leave comments, you need to log in
How to remove 3 first lines in csv file using PHP?
Hello! How to remove 3 first lines in csv file using PHP?
On the net I found only for one line:
<?php
$row_number = 0; //номер строки которую удаляем
$file_out = file("file.csv"); // Считываем весь файл в массив
//записываем нужную строку в файл
file_put_contents("file2.csv", $file_out[$row_number], FILE_APPEND);
//удаляем записаную строчку
unset($file_out[$row_number]);
//записали остачу в файл
file_put_contents("file.csv", implode("", $file_out));
?>
Answer the question
In order to leave comments, you need to log in
do the line to delete
three times , it will always be the first
Deleting a line in your code is a side effect, its main purpose is to save the first line you need to a new file.
It's easier to delete rows.
$file_out = file("file.csv"); //читаем нужный файл
$file = array_splice($file, 3); //удаляем 3 строки
file_put_contents("file.csv", implode("", $file)); //сохраняем в этот же файл
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question