What's the difference between \r and \n for inserting a line break in the HTML my PHP code outputs? I Googled and found a reference to using both, which I did first, then I tried each separately. All three methods output the same HTML for me - all exactly what I was looking for - a simple line break in the code between <li> tags.

But what's the difference? Should I use one over the other?

    \r is mac \n is linux and \r\n is winblows.

      For a linebreak in HTML, use <br> or <br/>

        I'm not trying to make a line break in the output seen in the browser by the user. I know all about <br> tags and HTML in general. My question wasn't as clear as needed, perhaps.

        I'm just trying to put a carriage return (line break) in the HTML code itself so it's easier to read. So, for instance, instead of:

        <li>Item</li><li>Item</li><li>Item</li><li>Item</li><li>Item</li>

        The PHP would write out the code this way:

        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>

        Incidentally - the first response answered half my question - that is what the difference in \r and \n is. The question remains, though, do I need all of them?

        Does the Mac, Linux, Windows element related to the platform I'm developing on? The web server that PHP is running on? The end users web browser platform? What?

        Either way - it doesn't seem to make sense 'cause I've used all three options separately and had them all work just fine on my local Mac that I'm developing and testing on. Questions, questions.

          Honestly, you don't need all of them. The most used is probably \n. Personally, my coding style is this:

          echo '<li>item</li>
          ';

          Now, in my code, without the \n I have a line-break in the source so thus the formatting is correct in my eyes. Not difficult to achieve 😉

          Honestly, it really shouldn't matter which of the 3 you use, but I believe \n is more widely accepted and used than \r or \r\n.

            Write a Reply...