PHP New Line will not work

前端 未结 3 1635
鱼传尺愫
鱼传尺愫 2020-12-07 04:16

Hi I am trying to create some code that first reads the existing contents of the file in and then adds the new line of code on a new line but the code i am using just adds i

相关标签:
3条回答
  • 2020-12-07 04:59

    Line endings per OS

    Unix / Linux
    \n

    DOS / Windows
    \r\n

    Invalid
    \r and \n\r


    The value of PHP_EOL constant depends on the platform php is running on.
    It doesn't detect the line-endings in the current file or anything magic.

    0 讨论(0)
  • 2020-12-07 05:00

    Instead of appending \n, concatenate the constant PHP_EOL which is always the correct newline character for the current platform.

    It might also be an issue with the program you're using to open the text file with. For instance, Notepad on Windows is incapable of understanding unix style newlines.

    0 讨论(0)
  • 2020-12-07 05:04

    I ran into this same issue. What application are you using to read the file? I found that for some reason Notepad (my default for .txt files) didn't recognize the "\n\r" escape characters. I opened my .txt file that I was writing to using Notepad++, Atom (my text editor of choice), or in a browser and they all showed the line breaks just fine.

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