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

前端 未结 7 1211
青春惊慌失措
青春惊慌失措 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:31

    When you run a PHP script in a browser, it will be rendered as HTML by default. If the books you’re using show otherwise, then either the code or the illustration is inaccurate. You can use “view source” to view what was sent to the browser and you’ll see that your line feeds are present.

    
    

    This will render in your browser as:

    Line 1 Line 2
    

    If you need to send plain text to your browser, you can use something like:

    
    

    This will output:

    Line 1
    Line 2
    

    PHP Linefeeds (\n) Not Working is referring to sending output to a file rather than the browser.

提交回复
热议问题