What is the difference between using '\n' and "\n" for line breaks in PHP?
Using '\n' in PHP will treat the backslash as a literal character and not interpret it as a new line, while "\n" will be interpreted as a new line character. Therefore, to create a line break in PHP, you should use double quotes around "\n" to ensure it is recognized as a newline character.
// Using double quotes for line breaks
echo "This is line 1.\nThis is line 2.";
// Output:
// This is line 1.
// This is line 2.
Related questions
-
PDO Symfony2 controllers
-
$HTTP_SESSION_VARS $_SESSION PHP
-
PHP form submissions display results