Entry
What does "\n" mean in PHP. I see it in code and have no idea what it does.
May 7th, 2002 22:05
David Price, ryan kaiser,
In PHP and many other programming languages the character \n indicates a newline.
so a code sample like this:
<?php echo( "this\n is\n a\n test\n" ); ?>
would result in output with each of these words on a separate line.
(The reason this works is that the \ character is interpreted as an "escaape" character. Whatever character directly follows a \ is interpreted as a special character. You need to use the escape character when you want to output a new line (\n), output a quote (\"), or even output a \ character (\\).
I hope this answers your question adequately.
(Note: windows files usually contain a carriage return character: \r as well as \n. Unix only uses \n.)
For another approach to the use of escape characters visit http://www.htmlgoodies.com/beyond/escapecharacter.html