jaymc Posted July 24, 2007 Share Posted July 24, 2007 On my site I have a system where members can post comments on each others profiles The problem Im having, if someone posts: testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt It will cause an x axis scroll bar because there is no break in the text Whats the best way to combat this, Im assuming it has to be PHP as HTML will always stretch the content to fit it in, regardess of width specifications I was thinkin of perhaps inserting an automatic <BR> after every 50th char, but the problem then it would cut genuine words in half if they fell into the 50th char So I would need to make it a bit more clever than that Any help would be great! Thanks Quote Link to comment Share on other sites More sharing options...
yarnold Posted July 24, 2007 Share Posted July 24, 2007 Use: wordwrap($text, 50, "<br />\n"); It won't split genuine words in half, unless you include the optional fourth parameter and set it to true... hope this helps Ed Quote Link to comment Share on other sites More sharing options...
suttercain Posted July 24, 2007 Share Posted July 24, 2007 You can also use CSS: http://www.w3schools.com/css/pr_pos_overflow.asp Quote Link to comment Share on other sites More sharing options...
jaymc Posted July 24, 2007 Author Share Posted July 24, 2007 Use: wordwrap($text, 50, "<br />\n"); It won't split genuine words in half, unless you include the optional fourth parameter and set it to true... hope this helps Ed This only works with words If someone just posts tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt It wont split it because that count as just one word It will work if I add 'true' in the function but that of course will split genuine words in half I think I need a way of detecting excesive letters Its safe to say any word that contains more than 3 consecutive letters is not a valid word, e.g hellooooooooo The CSS doesnt work either, it gives a scroll bar or still stretches the content, this cannot be In Invision Power Board you can do it, here is how they describe it Remove excess exclamation/question marks in topic titles? Will turn: This!!!!! into This! Any more suggestions? Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 24, 2007 Share Posted July 24, 2007 <?php $test="testtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"; if(strlen($test)>50){ $word=wordwrap($test,50,"<br>" ,true); } echo $word; ?> Quote Link to comment Share on other sites More sharing options...
jaymc Posted July 24, 2007 Author Share Posted July 24, 2007 <?php $test="testtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"; if(strlen($test)>50){ $word=wordwrap($test,50,"<br>" ,true); } echo $word; ?> Ok thats real good, however, to use that Im going to have to explode each comment by " " to dig out the words, then for each word do the strlen check Sure it will work, but do I need to worry about it using a hell load of resources The max amount of chars per comment is 1000 Its just my site is quite busy so the less resources my scripts use the better Should I worry about it? Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 24, 2007 Share Posted July 24, 2007 have a look at this ok. <?php $test="testtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"; echo "Total charecters ".strlen($test)." <br>"; if(strlen($test)>50){ $word=wordwrap($test,50,"<br>" ,true); } echo $word; ?> Quote Link to comment Share on other sites More sharing options...
jaymc Posted July 24, 2007 Author Share Posted July 24, 2007 Heres what Ive come up with $words = explode(" ", $comments[comment]); $wordarray = array(); foreach ($words as $words) { if(strlen($words)>35){ $words=substr($words, 0, 35); } $wordarray[] = $words; } $comments[comment] = join(" ", $wordarray); [code] Works a treat [/code] Quote Link to comment 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.