getting the first 25 words of a paragraph

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

getting the first 25 words of a paragraph

Post by psychotomus »

how can I get the first 25 words of a paragraph? I know i could use explod(string, " ") then run a for loop to combine the first 25, but theres probally a much simplier way.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

The str-word-count could be of help :idea:.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

or maybe a regular expression?

Code: Select all

^(\w+[\.,-?/{[}\]<>=_`~]?\w*\s){1,25}
visitor-Q
Forum Commoner
Posts: 72
Joined: Mon Feb 05, 2007 1:40 am

Post by visitor-Q »

have a look at strlen(), strpos(), and stristr(). you could also gain a little perspective from list() and each().
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Post Reply