0

I'm using PHP 7.2.10

I'm using Windows 10 Home Single Language 64-bit Operating System

I tried following two codes but I received the same output in both the cases :

Code 1 :

<?php

echo "stackoverflow\nnine" ;

?>

Code 2 :

<?php

echo "stackoverflow\rnine" ;

?>

Same output for both of the above programs :

stackoverflow
nine

As per my knowledge, Linefeed(\n) means to advance downward to the next line and Carriage return(\r) means to return to the beginning of the current line without advancing downward.

Then, why I am getting the same output for the things which are entirely different in nature and in meaning?

Why I'm getting the output with carriage return(\r) on the next line advanced downward?

Chris F Carroll
  • 11,146
  • 3
  • 53
  • 61
PHPLover
  • 1
  • 51
  • 158
  • 311
  • 3
    It's not PHP that determines what it does, it's the system. – aynber Oct 09 '18 at 15:28
  • 1
    They both do the same thing in practice (they *might* do something different if you've got an electronic typewriter) - `LF` is ACII 10 and `CR` ASCII 13; Unix used LF to end the line, old versions of Mac used CR - while Windows and MIME tend to use both as `CRLF` - [possibly relevant](https://stackoverflow.com/questions/1552749/difference-between-cr-lf-lf-and-cr-line-break-types) – CD001 Oct 09 '18 at 15:29
  • 1
    try running this code in a terminal, you will see the difference ;) – sietse85 Oct 09 '18 at 15:29
  • 1
    we also have a beautiful constant PHP_EOL which will make lineendings works on whatever OS PHP runs on – sietse85 Oct 09 '18 at 15:30

0 Answers0