In PHP I am trying to create a newline character:

echo $clientid;
echo ' ';
echo $lastname;
echo ' ';
echo '\r\n';

Afterwards I open the created file in Notepad and it writes the newline literally:

1 John Doe\r\n 1 John Doe\r\n 1 John Doe\r\n

I have tried many variations of the \r\n, but none work. Why isnt the newline turning into a newline?

Comments

possible duplicate of Print newline in PHP in single quotes

Written by Gordon

Accepted Answer

Only within double quoted strings the escape sequences \r and \n are recognized and replaced by 0x0D and 0x0A respectively, so:

"\r\n"

Single quoted strings do only know the escape sequences \\ and \'.

Written by Gumbo
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki