Page 1 of 1

How to show text from DB with <breaks>?

Posted: Tue Oct 10, 2006 6:44 pm
by toughguy
Hey guys,

Basically, I wrote a small custom forum program and I'm having problems getting the text to display properly. Obviously, when I get the text from the DB, the HTML outputs it in a straight line because it reads a space and every consecutive space after that as nothing.

One option was the <pre></pre> tags, but this is still a pain as it messes with the text cosmetics. The solution to that would be putting the <font></font> tage inside the <pre></pre> tag but the text is still one size bigger (I get a size 4 when I put a size 3) in IE.

Also using the <pre></pre> tags I'm forced to hack every line off after 70 columns or so using wordwrap().

The text is being sent to my server with the breaks intact (using <textarea name="message" cols="60" rows="20" id="message" wrap="virtual">), so I'm completely out of ideas.

I'm sure there's a really simple solution to this and I'm just really complicating things. If anyone has any ideas, let me know.

Thanks,

Dimitri Marshall

P.S. I would just install PHPBB but it's more than I need and I really don't feel like customizing it to the look and feel of my web site. I think solving this issue would be a lot easier, not to mention I like writting my own stuff to learn.

Posted: Tue Oct 10, 2006 6:52 pm
by RobertGonzalez
nl2br() perhaps?

Posted: Tue Oct 10, 2006 6:53 pm
by volka
linebreaks from a textarea are sent as \r\n (two special characters). html does not recognize these as linebreaks (except within <pre> elements).
see http://www.w3.org/TR/html4/struct/text.html#h-9.3.2 and http://de2.php.net/nl2br

As for the spaces take a look at http://www.w3.org/TR/html4/struct/text. ... 2[quote]In particular, user agents should collapse input white space sequences when producing output inter-word space. [/quote]spaces are not meant for formatting text.

Posted: Tue Oct 10, 2006 7:00 pm
by toughguy
Haha, of course it had to be that easy. Never heard of that function but works like a dream.

Thanks guys!

P.S. I was never trying to use space to format text, and I've never used the <pre> tag for anything aside from getting my forum to work :( .

D