Page 1 of 1

Limit length of a word/string (FIXED)

Posted: Thu Jan 21, 2010 4:59 pm
by synical21
Hey Guru's,

I have a small problem, if a user submits data which is 1 word but 600 charcters long it will run off my template and make the page width really wrong when that word is output. I would like to limit the size of words so they do not run outside my page. I have done some googleing and came across php's wordwrap so I tried to implement it.

Code: Select all

 
$theproof = nl2br($row['proof']);
echo wordwrap($theproof, 20, "<br />\n");
 
Have I done it wrong? Is there a better way? Just a little help please :drunk:

Re: Limit length of a word/string (FIXED)

Posted: Thu Jan 21, 2010 5:02 pm
by synical21
My bad I fixed it now, I forgot to use the parameter cut = TRUE E.G

Code: Select all

 
$theproof = nl2br($row['proof']);
echo wordwrap($theproof, 20, "<br />\n,",true);
 
If the cut is set to TRUE, the string is always wrapped at or before the specified width. So if you have a word that is larger than the given width, it is broken apart.