-1

echo("<li>Hello</li>\n"); seems to work fine for putting a new line in the HTML.

Is \r also required? For instance, echo("<li>Hello</li>\r\n");

Thanks

user1032531
  • 24,767
  • 68
  • 217
  • 387
  • 3
    It is for some systems particularly windows – John Conde Mar 21 '14 at 18:28
  • @JohnConde Does anyone have a resource that explains exactly when `\r` is used? I haven't found the need to use it in a Windows environment however I know I've seen it before. – Jasper Mar 21 '14 at 18:31
  • @JohnConde. Ah, I see. I must be using one of the browsers that work without it. – user1032531 Mar 21 '14 at 18:31
  • 2
    All browsers will translate the `\n` as a newline regardless of system if you see the source code, because it was rendered by the web server. You would only need the `\r\n` if you were writing that on a windows system and not using a web server to view the page. – Prix Mar 21 '14 at 18:33
  • 2
    When it comes to writing content to files on Windows, that's where it makes a more prominent difference. I quote from an entry on the [`PHP website`](http://www.php.net/fwrite) *"If you are writing data to a txt file on a windows system and need a line break. use \r\n"* – Funk Forty Niner Mar 21 '14 at 18:34
  • If you just want your HTML to show up as new lines in the source (*or to look "pretty" as you stated in another comment*) without having everything all clumped in single lines of code (*which I see all too often*) concatenate the last lines of code with `. "\n"` I.e.: `echo("
  • Hello
  • " . "\n");` and `echo "" . "\n";` etc. that way you'll get nicely formatted and aligned HTML. I see these mistakes (*day in and day out*) having some (*next to*) unreadable code when it comes to debugging HTML. Using `
    ` will print `
    ` in the source, while `\n` won't.
    – Funk Forty Niner Mar 21 '14 at 18:50