Entry
how do I insert a new line using "echo"?
Feb 2nd, 2001 23:38
Philip Olson, Ki - Hong Kim, ARantxa Salazar,
Have a look here :
http://www.php.net/manual/en/language.types.string.php
Notice the linefeed :
\n
This returns a new line. It's common to end a statement with it as to
create a new line, something like :
<?php
echo "<table>\n";
echo "<tr>\n";
echo "<td>hi</td>\n";
echo "</tr>";
echo "</table>\n";
?>
Within the source, that will look idential to this (btw, one should
break out of PHP and use HTML for this sort of thing, writing it as
follows in "HTML mode" works nicely and outputs as such) :
<table>
<tr>
<td>hi</td>
</tr>
</table>
Without the \n line feeds, the source would have looked like :
<table><tr><td>hi</td></tr></table>
There are many reasons to use \n but one reason to use it as above is
to create beautful HTML source code. The browser doesn't know the
difference but us humans do and when looking through the HTML source,
it is much easier to read. Also, using linefeeds within a mail()
message is important as well as various other uses. One note, the HTML
<pre> tag recognizes this spacing. One function that pertains to all
this is :
http://www.php.net/manual/en/function.nl2br.php
It converts linefeeds into <br>'s and works nicely for such things as
<textarea>'s when this is the desired effect. For an explanation of \n
have a look here :
Why does the echo command not give a line break in the browser
output for \n?
--------------------------------------------------------------
http://www.faqts.com/knowledge_base/view.phtml/aid/1046/fid/2