Answer the question
In order to leave comments, you need to log in
PHP. How to output variables line by line in CSV?
Good afternoon.
Tell me please, comrades. How to output variables line by line in CSV?
I have 2 variables in the chat bot $q (what we enter), $r (what the bot answers)
I want to log in a csv table in two columns $q and $r
How to write line by line to csv? So that the record is not overwritten, but continues below with a new line
Answer the question
In order to leave comments, you need to log in
How are you writing to the file? Most likely the write modifier is set to overwrite and to "overwrite"
$file = '/path/to/file/file_name';
$string = 'Тут ваша переменная';
if (file_exist($file)) {
file_put_contents($file, $string, FILE_APPEND | LOCK_EX); //Добавит строку в файл
} else {
file_put_contents($file, $string);//Создаст файл и положит в него строку
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question