I have a CSV file with:
Test1,One line
Test2,"Two lines
Hello"
Test3,One line
As you can see, one of the columns has a value which is separated with a new line.
To parse this CSV file into an array, I run:
$csvArray = array();
$csvData = file_get_contents('file.csv');
$lines = explode(PHP_EOL, $csvData);
foreach ($lines as $line) {
$csvArray[] = str_getcsv($line);
}
// print_r($csvArray);
It works beside one problem. It reads the new line in the value as a new row, which is completely incorrect.
How do I make it so that it properly reads a multi-line value?
Edit: this question focuses on new lines.