Page 1 of 1
PHP-MySQL-PHP: Line skipping/spacing
Posted: Wed Feb 26, 2003 3:33 pm
by evilmonkey
Hello.
If I use a form to input something (through PHP) into a MySQL database, and call on it to display, it comes out with screwed up line spacing. And line spacing is important every once in a while. I found I can eliminate this problem by putting the HTML tag <br> right into the form, but this is no good if a user is doing the input. How can this be done automatically when a user goes to the next line?
Cheers!
Posted: Wed Feb 26, 2003 4:13 pm
by volka
which form-element do you use? <input> or <textarea>?
Maybe you want
http://www.php.net/manual/en/function.nl2br.php
Posted: Wed Feb 26, 2003 7:26 pm
by McGruff
Yup nl2br() the text coming out of the database. We all get stuck on that one!
Posted: Thu Feb 27, 2003 6:12 pm
by evilmonkey
I don't really understand, can you give me an example?
I'm using textarea, and I want the <br> tag to appear whe a user goes to the next line.
Bieng more clear, the way the text is entered and retrieved now, where the line ends depends on the size of the ie/netscape winodw. I want it to end whereever the user wanted it it to end.
Thanks.
Posted: Thu Feb 27, 2003 6:43 pm
by McGruff
wordwrap()?
Never used that much since it doesn't work on my local windows server for some reason but it might help.
Posted: Thu Feb 27, 2003 9:03 pm
by evilmonkey
No, that does not help. This is what i already have. The nl2br was on the right track, i just don't understand how to use it.
Thanks for trying though.
Posted: Thu Feb 27, 2003 9:57 pm
by McGruff
When you retreive text from the database, you'll have something like:
$result = mysql_fetch_array($query);
$text = $result['text'];
replace with
$text = nl2br($result['text']);
If you addslashed on the way in, don't forget to striplash as well.
Posted: Fri Feb 28, 2003 12:57 am
by decoy1
If that doesn't work, add wrap="physical" to the textarea tag
Posted: Fri Feb 28, 2003 2:36 am
by twigletmac
You don't really want to have <br> tags appearing in the text area because although you can't see it newlines characters are being added each time the person presses enter. What nl2br() does is, when you want to redisplay this information, it adds an HTML linebreak (<br />) next to the newline character so not only does the source have the newlines apparent, the output on the screen does too.
Mac
Posted: Fri Feb 28, 2003 2:38 pm
by evilmonkey
McGruff, thank you very much m8, that worked. Thanks to everyone else who contributed to the topic as well.