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! 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 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] 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! 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
Archived
This topic is now archived and is closed to further replies.