What is the difference between '\r\n' and "\r\n" in PHP and how does it affect text formatting?
In PHP, '\r\n' is a string with single quotes, treating the characters '\r' and '\n' as literal characters. On the other hand, "\r\n" is a string with double quotes, interpreting '\r' as a carriage return and '\n' as a new line character. When used in text formatting, '\r\n' will not create a new line, while "\r\n" will properly format text with a line break.
// Using double quotes to properly format text with a line break
$text = "Line 1\r\nLine 2\r\nLine 3";
echo $text;
Related questions
-
debugging tools parsing errors PHP code
-
autoincrementing ID field MySQL table selecting random winners
-
function terminate prematurely