Line break not working when writing to text file in PHP

后端 未结 4 1094
执念已碎
执念已碎 2020-12-03 02:34

I have the following test script:



        
相关标签:
4条回答
  • 2020-12-03 03:14

    It is best to use PHP_EOL. This is cross-platform, so it automatically chooses the correct newline character(s) for the platform PHP is currently running on.

    $stringData = "Floppy Jalopy" . PHP_EOL;
    

    PHP Constants

    0 讨论(0)
  • 2020-12-03 03:21

    Your code runs fine.

    Use Notepad2 or Notepad++ if you're working on Windows. The built-in Notepad is unable to cope with Unix-style line endings.

    0 讨论(0)
  • 2020-12-03 03:23

    . PHP_EOL; will work universally

    0 讨论(0)
  • 2020-12-03 03:31

    If you want to open the file in Windows notepad, you must use Windows line breaks: \r\n

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