0
   

What does \n mean in PHP Code?

 
 
Reply Thu 23 Mar, 2006 06:56 pm
I'm looking at spme PHP code, and I can't figure out what /n means

Example:
echo "<font class=\"content\" color=\"#505050\">$boxstuff</font>\n";

It doesn't seem to need to be there because the code works fine without it. Why would it be there?
 
  1  
Reply Fri 24 Mar, 2006 01:24 am
It means 'new line' ie a line break.
0 Replies
 
View Profile Monger
 
  1  
Reply Sat 25 Mar, 2006 02:45 pm
\n as used above will add a line break to the source code output, as opposed to a <br> tag which will add a line break to the resulting visual display.
0 Replies
 
  1  
Reply Fri 31 Mar, 2006 02:05 am
OK, I get it but I can't think of why I would ever need to use \n in my code. Is it just proper to use it, like it's proper to use quotes around tag values even though it works without them.
  1  
Reply Fri 21 Aug, 2009 04:26 pm
It eliminates "whitespace". When you are writing xhtml with php and you want your lines of code to look organized when they are spit out of the server, you can hit "tab" a few times (or use /t), or a carriage return (but using /n consumes less space and doesn't create white space in your code).
0 Replies
 
  1  
Reply Wed 26 Aug, 2009 05:54 am
print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&GuestBook=";
for ($n = $NumLow; $n < $NumHigh; $n++) {
print $DataArray[$n];
if (!$DataArray[]) {
Print "<br><br><b>No More entries</b>";
exit;
}
}
?> etc,,,,,,,,, More Details : Edit [Moderator]: Link removed
0 Replies
 
  1  
Reply Wed 26 Aug, 2009 06:43 am
The /n really isn't in your code, it's in the output HTML. It's just an HTML format code.
0 Replies
 
  1  
Reply Fri 18 Sep, 2009 12:54 pm
In addition to what everyone has said, it is important to know that there are two types of strings in PHP. Strings made with double-quotes (") and strings made with single-quotes ('). When you write
Code:
<?php
print 'This is my string.\n';
print '<br />';
print "This is my string\n";
?>

You'll notice you get two different looking strings. The HTML output formatting characters (such as \n and \t and many others) only work with double-quotes. However, if you're like me, and use single-quoted strings more often to alleviate much of the difficulty debugging and diagnosing problems with a program, like for instance having to escape so many friggin double-quotes when I write HTML embedded in PHP code
Code:
<?php
print "<font size=\"12\" color=\"#000000\">I said, \"Hey!\"<br />";
?>

Seriously, that looks disgusting.
You can have the best of both worlds by doing concatenating the string like this:
Code:
<?php
print 'This is my string.'."\n";
?>

This will join the two types of strings together and allow you to format your webpage AND your HTML code in the same line.
Also, when formatting an email to send using PHP, if you're not using HTML formatting for your email, the standard newline character for emails is: \r\n
Again, to be used with double-quotes, not single-quotes.
0 Replies
 
 

Related Topics

Displaying <?php in javascript. - Discussion by BobbyDouglas
Installing PHP with IIS - CGI Error - Discussion by skinnz
PHP: Cookie Problem - Discussion by BobbyDouglas
PHP Debate - Discussion by Craven de Kere
What does the PHP code \n"; ?> mean? - Question by Steve Boulton
Random avatar script - Discussion by Craven de Kere
PHP/MySQL tutorials - Discussion by filfish
PHP language - Discussion by vonderjohn
 
  1. able2know
  2. » What does \n mean in PHP Code?
Copyright © 2009 Horizontal Verticals :: Page generated in 0.33 seconds on 11/22/2009 at 05:38:42 Top End