PDA

View Full Version : text limiting


runnerjp
05-30-2008, 09:48 PM
i was wondering atm when $message is brought up and say 400 characters are placed into it via post it will display 400 carachters in 1 long line... is there away to make it so after so many charaters it starts a new line like on this forum so the text can only go so far?

zfred09
05-30-2008, 10:40 PM
Ahhhh, this is a wonderful problem that I struggled to fix and understand. First, don't look at HTML when trying to solve this problem, HTML/CSS will automatically (With fixed width) start new lines. To fix this PHP has a nice function call wordwrap(). I used it like this...

$text = wordwrap($text, 35, "**"); //Where $text is your text that was submitted, 35 is the # of chars before a word wrap, and ** is the break(default is \n)

$arr = explode('**', $text);

Look it up at the URL below for more info.

http://us.php.net/manual/en/function.wordwrap.php