Importing CSV that has line breaks within the actual fields

后端 未结 6 1980
挽巷
挽巷 2021-02-20 08:23

I am using PHP to import a CSV file, which originates from an excel spreadsheet. Some of the fields contain line breaks in them, so when I reopen the csv in excel / open office

6条回答
  •  春和景丽
    2021-02-20 08:40

    I had that problem too and did not find an way to read the data correctly.

    In my case it was an one-time-import, so i made an script that searched for all line-breaks within an column and replaced it with something like #####. Then I imported the data and replaced that by linebreaks.

    If you need an regular import you could write you own CSV-Parser, that handles the problem. If the text-columns are within "" you could treat everything between two "" as one columns (with check for escaped " within the content).

提交回复
热议问题