0

I'm using a CSV file to enter various things such as image filenames or descriptions to pull into variables for my site.

if (($handle = fopen("properties/properties.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $row++;
    $num = count($data);

        ${'property'.$row.'mainimg'} = '"'."properties/".$data[0].'"';
        ${'property'.$row.'col1desc'} = $data[1];

    for ($c=0; $c < $num; $c++) {

    }
}
fclose($handle);
}

I'm using Excel 2010 to edit the .csv. When I put in text like this into a cell:

line 1
line 2
line 3

it's saved into the .csv like this (copy paste from notepad):

"line 1
line 2
line 3"

and comes out like this on my page:

line 1 line 2 line 3

What can I do to display these multiple lines from a single cell in the .csv?

Thanks!

1 Answers1

2

Do not use fgetcsv. Csv is designed to take line break as different row, and your attempt using it with new line character in a field will go nowhere. Try file_get_contents first, explode with "\"\n\"" (line break enclosed by quoteation mark) then explode with "," again.

Moe Tsao
  • 1,054
  • 6
  • 9