floridaflatlander Posted October 1, 2011 Share Posted October 1, 2011 I have a div 120px in width that contains a thumb nail and a title under it. My problem is if a word in the title is over X (20+ I think) characters the div gets wider to hold all the characters in a word. I can limit the string length with substr, but I want to limit the length of a word in a string. How do I limit a words length? Thanks S Quote Link to comment https://forums.phpfreaks.com/topic/248228-how-can-i-limit-word-length/ Share on other sites More sharing options...
trq Posted October 1, 2011 Share Posted October 1, 2011 With substr. Quote Link to comment https://forums.phpfreaks.com/topic/248228-how-can-i-limit-word-length/#findComment-1274661 Share on other sites More sharing options...
floridaflatlander Posted October 1, 2011 Author Share Posted October 1, 2011 How would I use substr() to limit word length? I can use it to limit a string like $title = substr ($title, 0, 100); But I want to limit the size of a word in the string. So if I have var thats $title = " A Cow Jumped Over The Mooooooooooooooooooooooooooooooooon" how can I change it to " A Cow Jumped Over The Mooooooooooo oooooooooooo oooooooooon" for the reason listed above. Thanks for the reply Quote Link to comment https://forums.phpfreaks.com/topic/248228-how-can-i-limit-word-length/#findComment-1274676 Share on other sites More sharing options...
Buddski Posted October 1, 2011 Share Posted October 1, 2011 wordwrap() Quote Link to comment https://forums.phpfreaks.com/topic/248228-how-can-i-limit-word-length/#findComment-1274678 Share on other sites More sharing options...
Pikachu2000 Posted October 1, 2011 Share Posted October 1, 2011 CSS: <div style="word-wrap:break-word;"> Quote Link to comment https://forums.phpfreaks.com/topic/248228-how-can-i-limit-word-length/#findComment-1274679 Share on other sites More sharing options...
floridaflatlander Posted October 1, 2011 Author Share Posted October 1, 2011 Thanks All The {word-wrap: break-word;} worked like a charm however I check with w3.org and it said "Property word-wrap doesn't exist :" But I'm still going to use it, I played with it in ie7, 8 & firefox and it worked great. I looked at php.net and wordwrap() may not do what I want because even though the index page will have thumbnails the picture page would need the full unbroken title or there abouts because the picture would have more room on it's own page. Thanks again I'm going to work with them both more as I get more time tonight and tomorrow. Quote Link to comment https://forums.phpfreaks.com/topic/248228-how-can-i-limit-word-length/#findComment-1274707 Share on other sites More sharing options...
floridaflatlander Posted October 1, 2011 Author Share Posted October 1, 2011 I'll mark this solved Quote Link to comment https://forums.phpfreaks.com/topic/248228-how-can-i-limit-word-length/#findComment-1274713 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.