PHP generating csv not sending correct new line feeds

后端 未结 3 1131
醉梦人生
醉梦人生 2021-02-08 00:51

I have a script that generates a csv file using the following code:

header(\'Content-type: text/csv\');
header(\'Content-Disposition: attachment; filename=\"\'.d         


        
相关标签:
3条回答
  • 2021-02-08 00:55

    I experienced the same issue. Later I replaced
    single quotes ' with double quotes " building $content variable.

    i.e. Keeping outer quotes rather double than single in $content variable.

    And it worked :)

    0 讨论(0)
  • 2021-02-08 00:59

    Be sure to use double quotes around the \r\n, not the single quotes as mentioned in the previous answer!

    0 讨论(0)
  • 2021-02-08 01:11

    Use "\r\n". (with double quotes)

    The above is the ascii characters for carriage return + line feed.

    Historically this relates to the early days of computing on teletypes when the output was printed to paper and returning the carriage of the teletype head to the start of the line was a separate operation to feeding a line through the printer. You could overwrite lines by just doing a carriage return and insert blank lines by just a line feed. Doing both returned the head to the start of the line and fed it a new line to print on.

    What precisely was required differed between systems -

    • Line feed only: - most Unix like systems
    • Carriage return plus Line feed: - DEC amd MS-DOS based systems
    • Carriage return only: - Early Apple/Mac OS's

    So what you're generating at the moment is a newline on a Unix system only. Wikipedia has quite a good page on this.

    There's actually unix command line tools to do the conversion too. The unix2dos and dos2unix commands convert ascii text files back and forward between the unix and dos formats by converting line feed to line feed plus carriage return and vica versa.

    0 讨论(0)
提交回复
热议问题