Code: Select all
echo 'a\nb';
and
Code: Select all
echo "a\nb";
Can anybody explain this behavior? and how can one print newline character? I've always used <br>. thanks
Moderator: General Moderators
Code: Select all
echo 'a\nb';
Code: Select all
echo "a\nb";
Code: Select all
<br />single quotation marks indicate to PHP that you want it to treat the string literally, variables and escape sequences will not be parsed and the string is simply outputted as it is (the exception being when using backslashes to escape)global_erp_solution wrote:AFAIK, \n is global convention for newline. butproduces a\nbCode: Select all
echo 'a\nb';
andproduces abCode: Select all
echo "a\nb";
Can anybody explain this behavior? and how can one print newline character? I've always used <br>. thanks
Backslashes stay with only two exceptions: \' and \\.Grizzzzzzzzzz wrote:single quotation marks indicate to PHP that you want it to treat the string literally, variables and escape sequences will not be parsed and the string is simply outputted as it is (the exception being when using backslashes to escape)
Code: Select all
echo '\a\p\o\s\t\r\o\p\h\e\:\ \'\,\ \b\a\c\k\s\l\a\s\h\:\ \\';Code: Select all
\a\p\o\s\t\r\o\p\h\e\:\ '\,\ \b\a\c\k\s\l\a\s\h\:\ \PHP does not interpret HTML entities.Grizzzzzzzzzz wrote:strings in double quotation marks are parsed for variables and the like, and so sequences such as \n or are interpreted.
oopsrequinix wrote:PHP does not interpret HTML entities.Grizzzzzzzzzz wrote:strings in double quotation marks are parsed for variables and the like, and so sequences such as \n or are interpreted.