Forum Moderators: coopster

Message Too Old, No Replies

What does \n really mean?

\n php mean

         

matthewamzn

7:25 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



This value seems to come up a lot and I'm not quite sure what it's meaning is.

\n

Example of script using this value:
Hello, {name}!\n{%FIELDS%}\n-- \nWith best regards,\nHawk

[edited by: matthewamzn at 7:30 pm (utc) on Aug. 9, 2005]

trillianjedi

7:26 pm on Aug 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd guess that it stands for "newline". What is does is stick a carriage return at the end of the ECHO statement, meaning the next ECHO statement will output on a new line.

TJ

coopster

7:39 pm on Aug 9, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You can really see the difference when you use it within HTML's <pre> tags.

<?php 
for ($i=1; $i<=5; $i++) {
print "\$i is: $i";
}
// Now with <pre> tags:
print '<pre>';
for ($i=1; $i<=5; $i++) {
print "\$i is: $i\n";
}
print '</pre>';
?>

This is handy stuff to know, especially when you start using functions like PHP's print_r() [php.net] function to dump arrays out. It makes them much easier to read in your browser.

jatar_k

1:10 am on Aug 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



let's not confuse newlines and carriage returns as they are very different

this thread talks a bit about what they are
CRLF vs LF [webmasterworld.com]