We all have to start somewhere with a new language
The problem you have here isn't actually PHP related, but HTML.
Both \r and \n work as you'd expect in PHP itself, for example, from a console window, try:
php -r 'echo "This is line one\nThis is line 2\n";' |
and you'll get:
This is line one
This is line 2 |
Same as if you run a PHP script a non-web environment.
HTML however, requires tags rather than escape codes, and that's why '<br />' works for you there rather than a \n or \r.
I assume you're running the code in a web environment, and although you're echoing data from PHP, it's actually being rendered by the HTML engine.
If you really want to use \r or \n in a web environment, you'll need to either wrap the 'echo' statement(s) in <pre></pre> tags, or define a text content type ( header('Content-type: text/plain'); ). Different situations / results that you're looking for would depend on what method was actually required, but if you're looking to generate HTML output, just continue with the '<br />' tag and all will be well
Just FWIW.. PHP also comes with a 'nl2br()' function that will convert newline codes to '<br />' tags. Useful when reading plain text in to display as HTML (for example, a basic news article stored in a database with no HTML tags or parsing a plain text document etc).
HTH
Regards,
Ian