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?


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:


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 community.
It is licensed under cc-wiki