Line breaks in PHP "\n"
with double quotes works perfectly.
echo "Primera linea php a separar de la segunda"."\n";
But with single quotes, it doesn't work
echo 'Primera linea php a separar de la segunda"."\n';
It throws the following error message
Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting ',' or ';' in C:\xampp\jobs\index.php on line 38
Documentation
According to the PHP Official Site .
What does this tell us?
Any character that is enclosed in single quotes will be taken as a literal character and its content will not be interpolated .
Possible solutions
Result
Explanation
Ignoring the fact of the single quote restriction, you can either use the concatenation operator
.
(dot) and add a newline to the string, or you can use the constantPHP_EOL
whose meaning is derived from the wordEnd Of Line
, which will add at the end of your text a line break.Online example!
is misspelled if you start a string with ''(single quotes) you must start and end with single quotes
your mistake is putting double quotes in a str with single quotes