V
V
Vlad Nesterenko2021-07-20 13:27:39
PHP
Vlad Nesterenko, 2021-07-20 13:27:39

How to read CSV file with line breaks in cells?

There is a CSV file where the last cell has line breaks (a lot of line breaks in one cell), I would like to read exactly these transfers into the array, so that later I could work with them (at the moment it reads everything in one line), I can’t solve this issue.
Example code how to read the file:

$handle = fopen("lun.csv", "r"); 
  $price_stock = array();
  while (($line = fgetcsv($handle, 0, ';')) !== FALSE) { 
      
  $price_stock[] = $line; //Записываем строчки в массив
  }

this is what it outputs:
radio|Additions to the bed L-179|no drawer|0|10.000|0|+|0.0000|+|0|+|0.00000000|no_image.jpg radio|Additions to the bed L-179|box for laundry| 0|10.000|0|+|1280.0000|+|0|+|0.00000000|no_image.jpg radio|Additions to the bed L-179|2 box for linen|0|10.000|0|+|2560.0000|+|0|+ |0.00000000|no_image.jpg radio|Slat spacing L-179|Reinforced slat 2.5 cm for double beds|0|10.000|0|+|480.0000|+|0|+|0.00000000 radio|Slat spacing L-179|Standard (5-5.5 cm)|0|10.000|0|+|0.0000|+|0|+|0.00000000|no_image.jpg
I would like :
radio|Additions to bed L-179|without box|0|10.000| 0|+|0.0000|+|0|+|0.00000000|no_image.jpg
radio|Additions to bed L-179|linen drawer|0|10.000|0|+|1280.0000|+|0|+|0.00000000|no_image. jpg
radio|Additions to the bed L-179|2 box for linen|0|10.000|0|+|2560.0000|+|0|+|0.00000000|no_image.jpg
radio|Spacing between slats L-179|Reinforced slat 2.5 cm for double beds beds|0|10.000|0|+|480.0000|+|0|+|0.00000000
radio|Slat spacing L-179|Standard (5-5.5 cm)|0|10.000|0|+|0.0000|+| 0|+|0.00000000|no_image.jpg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question