tags:

views:

67

answers:

2

Why have 2 functions that does the same thing? They both add a linebreak.

Any diffrence between them?

+2  A: 

One is a carriage return, and the other is a new line. They're different but may be treated similarly depending on your environment/language.

Jonathan Sampson
+10  A: 

This has nothing to do with PHP, and is a consequence of history :

  • UNIX / Linux use \n for linebreaks
  • Mac (before OSX) used \r
  • And windows uses a combinaison of both

PHP has just kept that behavior -- so it can work with those different OSes and their files.


Also, note :

  • Those are not functions : they are (special) characters
  • They are not exactly the same thing :
  • and, btw, those are another consequence of history : look at their names, and think about typewriters ;-)
Pascal MARTIN
Only Mac OS until 9 used `\r`; Mac OS X uses `\n`.
Gumbo
@Gumbo : didn't know that (but makes sense, as OSX is based on BSD) ; I edited my answer to reflect your note ;; thanks !
Pascal MARTIN
@Frederik : no, I edited my answer -- once again, I learnt something while giving an answer ^^ (And that's great ! )
Pascal MARTIN
@Fredrik If you edit your answer soon enough after posting, SO doesn't show the *EDITED* box. @Pascal edited his answer in response to @Gumbo's feedback.
Doug Neiner
@Doug, @Pascal: So I noticed, that is why I removed the comment.
Fredrik