\n -> <br>?
Moderator: General Moderators
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
\n -> <br>?
Still working on my forum/guestbook/messageboard thingy. Ig ot the tags, wprking liek i want, so far, but now what i want to do, is sot aht when a user hits the return key and skips lines, to replace those with <br> I've tried replaceing \n, \r, and \n\r, but nothing seems to work.. anyone got any ideas?
Thanks
Thanks
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
nl2br() in my eyes.
you can just pull the column name where your "messages" are stored in your sql table n hit it with this:
you can just pull the column name where your "messages" are stored in your sql table n hit it with this:
Code: Select all
<?php
$message = nl2br($row["message"]);
?>-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
well, one place where i use it is when writing to a file, and i want things on sepereate lines. You can't use <br> there because it is jsut a plain .txt file. So I have to use \n\r to skip a line. And also when writing PHP and your echoing HTML you might add a \n tot he end to keep your HTML clean - when someoen views your source it wont be all on one line, it will be on sepereate lines...
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
<br> is HTML, it will be shown in the browser as a newline.
\n is a application newline, meaning anything outside of a browser (notepad, command line, etc)
\r is a windows version of a linebreak.
say you're coding in c++, you're not going to use <br> if you want to space something out in the command prompt; you'd use \n.
edit - a typical use for this is when you're outputting lots of HTML, and don't want it to look messy in notepad:
would print out everything inside the for loop on one line
add a "\n" inside the echo statement however, and it makes a line break each time it runs through.
\n is a application newline, meaning anything outside of a browser (notepad, command line, etc)
\r is a windows version of a linebreak.
say you're coding in c++, you're not going to use <br> if you want to space something out in the command prompt; you'd use \n.
edit - a typical use for this is when you're outputting lots of HTML, and don't want it to look messy in notepad:
Code: Select all
<?php
echo "<table width="200" height="200">";
for($i=0;$i<$rows;$i++){
echo "<tr><td>" . $stuff[$i] . "</td></tr>";
}
echo "</table>";add a "\n" inside the echo statement however, and it makes a line break each time it runs through.
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm