corillo181 Posted May 29, 2006 Share Posted May 29, 2006 is there any way that i can word wrap when someone puts in more than the td can handle on width..beacuase if i gave a person a limit width to write and they write one long word together the td just expands to try and fit it all..is there any way that i can use something to say on how many charaterc to cause a line breake.. Link to comment https://forums.phpfreaks.com/topic/10722-word-wrap/ Share on other sites More sharing options...
Barand Posted May 29, 2006 Share Posted May 29, 2006 wordwrap() function[code]$text = 'supercallifragilisticexpiallidocious is a good word to test wordwrap function';$width = 20;echo wordwrap($text,$width,'<br/>',1);[/code] Link to comment https://forums.phpfreaks.com/topic/10722-word-wrap/#findComment-40043 Share on other sites More sharing options...
corillo181 Posted May 29, 2006 Author Share Posted May 29, 2006 add that was easier than i ha din mind.. thanx..oh but the bad thing is that it wraps every x number no matter what..ever if the word doesn't tke the spot and its the x number it wraps.. can there be any way to use it only if one word take more than it supossed to? Link to comment https://forums.phpfreaks.com/topic/10722-word-wrap/#findComment-40054 Share on other sites More sharing options...
Barand Posted May 29, 2006 Share Posted May 29, 2006 You would have to to get the word lengths and check them to see if the max length was exceeded[code]function max_word($text) { $words = explode(' ',$text); foreach($words as $w) { $sizes[] = strlen($w); } return max($sizes);}$text = 'supercallifragilistic expiallidocious is a good word to test wordwrap function';$width = 20;if (max_word($text) > $width) echo wordwrap($text,$width,'<br/>',1);else echo $text;[/code] Link to comment https://forums.phpfreaks.com/topic/10722-word-wrap/#findComment-40061 Share on other sites More sharing options...
corillo181 Posted May 29, 2006 Author Share Posted May 29, 2006 nice. but one more thing if i put it in the text that it's ben out put it litterary puts out the <br> so everyone can see there is a br..so should i do the function before the text goes in to the database? Link to comment https://forums.phpfreaks.com/topic/10722-word-wrap/#findComment-40073 Share on other sites More sharing options...
Barand Posted May 29, 2006 Share Posted May 29, 2006 Don't store text with '<BR>' in the database. Do the formatting on output. Link to comment https://forums.phpfreaks.com/topic/10722-word-wrap/#findComment-40076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.