Hi,

I've got a script to export a table to csv, but I'm having problems with one of the fields. The field is a Text field that had line breaks in it. This causes problems when importing the csv to excel because it treats each \n as the end of a row.

I tried doing a split and join by replacing '\n' with something else, but it didn't seem to replace all line breaks.

Does anyone have a solution for this?

Thanks for any help,
~Oni.

    I'd like to see what you tried that didn't replace all, but this should work:

    $file_txt = file_get_contents('file.csv');
    $res = file_put_contents('backup_file.csv', $file_txt);
    if ($res === filesize('file.csv') {
        $lines = file('file.csv', IGNORE_NEW_LINES)
        foreach ($lines as & $l) {
            $l = str_replace("\n", 'something else', $l);
        }
        unset($l);
        $lines = implode("\n", $lines);
        file_put_contents('file.csv', $lines);
    }
      Write a Reply...