formatting output text from textarea

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

formatting output text from textarea

Post by pleigh »

hii there,

i would like to know how i can format the output text coming from the text area.i have a forum-like program, if i add a thread, type the message, i like to view the output like how it appeared when i typed it in the textarea.what happens to me is that everytime i type some words, strike the return/enter key, the output is not how it was typed but instead, the new line becomes a space. i am really confused,maybe i'll put an example.

i like
some text
some text
some text
to appear like the above format.

my problem is, when i do it(strike the return/enter key) after each some text word,this is how it appears:
some text some text sometext
i hope you guys can help me..

thanks

pleigh
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

nl2br();

remember html only does what you tell it to, it does not respond to whitespace in strings unless you tell it.
jonemo
Forum Commoner
Posts: 28
Joined: Wed Feb 09, 2005 1:32 pm
Location: london, uk

Post by jonemo »

you could use <pre></pre> if you want to show whitespaces and tabs used in the textarea, but if you just want the kline breaks, then nl2br() is the right joice.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Or if you want to have enhanced options you could look for HTML Text Areas by

Googling for HTMLArea.

Another alternative is

http://www.kevinroth.com/rte/demo.htm

These might be overkill but I thought I'd let you know about them.
Post Reply