View Full Version : long strings of user input breaks formatting

03-14-2008, 05:49 PM
I have TEXTAREA input fields

Users can submit data.. if a long string is entered without spaces (like a URL) the string goes beyond the width of the div container.

what is a stylistically pleasing way to prevent this from occurring?

I assume exploding each word with a space and then counting the length of each word in the data. if length of a word is larger than a certain integer then add ' ...' a space followed by 3 periods

Is there another way of doing this than the way I described above?

03-14-2008, 05:50 PM

03-14-2008, 10:53 PM
If you don't want to wrap URLs you could do something like this:

$str = 'http://www.loooooooooooooooongurl.com/';
echo strlen($str) > 20 ? substr($str, 0, 20) . '...' : $str;
Where "20" is the string length limit. You could make it a variable if you want to be able to only change it in once place.