27
   

What does \n mean in PHP Code?

 
 
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?
 
hingehead
 
  2  
Fri 24 Mar, 2006 01:24 am
It means 'new line' ie a line break.
0 Replies
 
Monger
 
  3  
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
 
roverroad
 
  1  
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.
psperkins
 
  1  
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
 
Webdevelop
 
  -1  
Wed 26 Aug, 2009 05:54 am
@roverroad,
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
 
engineer
 
  1  
Wed 26 Aug, 2009 06:43 am
@roverroad,
The /n really isn't in your code, it's in the output HTML. It's just an HTML format code.
0 Replies
 
intoitdaily
 
  1  
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
 
monbasala
 
  1  
Wed 27 Oct, 2010 10:40 am
Format the HTML
0 Replies
 
katerinak955
 
  -1  
Fri 26 Nov, 2010 10:50 pm
Hi,
can anybody tell me what does the '\r\n' mean? for example:
Header("Location: Edit [Moderator]: Link removed\r\n");
any impact if i add/remove the '\r\n' in the header?

Thanks,
Katerina,
Edit [Moderator]: Link removed
hingehead
 
  2  
Fri 26 Nov, 2010 11:02 pm
@katerinak955,
\n = linefeed or new line
\r = carriage return (like pressing enter)

This might help: http://www.go4expert.com/forums/showthread.php?t=8021
0 Replies
 
saramartin
 
  -1  
Mon 18 Apr, 2011 11:39 pm
in php code /n use for the newline character.
phpdeveloper
 
  0  
Mon 23 Jan, 2012 02:01 am
@roverroad,
it uses for newline...
0 Replies
 
negikaithal
 
  1  
Sat 6 Oct, 2012 08:35 am
@saramartin,
but it not work in php why any example
hingehead
 
  1  
Sat 6 Oct, 2012 05:02 pm
@negikaithal,
Not /n

\n
0 Replies
 
robertpuzio
 
  3  
Thu 25 Oct, 2012 03:54 am
@roverroad,
\n is the newline character, \t is the tab character. It's usually use for formatting html. eg,

echo "<html>\n<head>\n</head>\n<body>\n\t<div>\n\t</div>\n</body>\n</html>";
0 Replies
 
Rose G
 
  1  
Wed 6 Mar, 2013 12:44 am
@roverroad,
"\n" is used in PHP to create a new line or you can say its just a old line break.
Ex: Suppose you want to write like:
Address:
Plot No:1203
Mumbai
India

So your coding line like:
echo "Address: \n";
echo "Plot No:1203 \n"; ......
0 Replies
 
dreamcyberdci
 
  0  
Sun 31 Mar, 2013 11:31 pm
@roverroad,
\n means new line character

Basic code of PHP
<?php //on

//and

//off ?>
hingehead
 
  2  
Mon 1 Apr, 2013 06:32 am
@dreamcyberdci,
http://everyboty.net/shared/pics/do%20you%20have%20any%20idea%20how%20fast%20you%20were%20scrolling.jpeg
0 Replies
 
denshidan
 
  1  
Sat 11 Jan, 2014 09:43 am
there is also a PHP constant called PHP_EOL that puts a carriage return in generated code for readability

eg

echo "<div id='mydiv'>".PHP_EOL . "hello" . PHP_EOL . "</div>";

outputs

<div id='mydiv'>
hello
</div>

0 Replies
 
 

Related Topics

\n - Question by negikaithal
PHP question about parse_url - Question by markalanbaker1
PHP Debate - Discussion by Craven de Kere
PHP: Cookie Problem - Discussion by BobbyDouglas
Installing PHP with IIS - CGI Error - Discussion by skinnz
Displaying <?php in javascript. - Discussion by BobbyDouglas
php software - Question by aishna
 
  1. Forums
  2. » What does \n mean in PHP Code?
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 11/07/2024 at 10:14:01