guttyguppy Posted January 23, 2007 Share Posted January 23, 2007 Let's say I want a brief portion of a paragraph of text to show up on my homepage. The paragraph is in a mysql database and may have anywhere from 100 to 1000 words, whatever. I just want the first 15 or so. I know I can use substr to get a certain number of characters, but I may end up with the last word getting cut off. I want to make sure the 15th word is a whole word. Is there an easy way to do this? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/35373-how-to-select-first-15-words-of-a-paragraph/ Share on other sites More sharing options...
trochia Posted January 23, 2007 Share Posted January 23, 2007 $count 0-15, $display Quote Link to comment https://forums.phpfreaks.com/topic/35373-how-to-select-first-15-words-of-a-paragraph/#findComment-167185 Share on other sites More sharing options...
complex05 Posted January 23, 2007 Share Posted January 23, 2007 [code]$textarea = "this is some text with 15 words in it";$words = split(" ",$textarea);for($i=0; $i<15; $i++){ echo $words[$i];}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35373-how-to-select-first-15-words-of-a-paragraph/#findComment-167190 Share on other sites More sharing options...
guttyguppy Posted January 23, 2007 Author Share Posted January 23, 2007 Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/35373-how-to-select-first-15-words-of-a-paragraph/#findComment-167430 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.