New line (“\n”) in PHP is not working

前端 未结 7 1212
青春惊慌失措
青春惊慌失措 2020-12-08 22:41

For some strange reason, inserting echo \"\\n\"; and other scape sequence characters are not working for me, that\'s why I am just using

7条回答
  •  青春惊慌失措
    2020-12-08 23:15

    The echo "\n" is probably working, just not the way you expect it to.

    That command will insert a new line character. From the sounds of it, you're using a browser to view your output. Note that if you wrote an HTML file that had a body contents that looked like:

    This is a test

    The browser rendering would not include the new lines, and would instead just show "This is a test"

    If you want to see the newlines, you could view source, and you'll see that the source code includes the new lines.

    The rule of thumb is that if you need new lines in a browser, you need to use HTML (e.g.
    ), while if you want it in plain text, you can use the \n

提交回复
热议问题