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
HormonX
Forum Commoner
Posts: 50 Joined: Tue Dec 10, 2002 7:43 pm
Location: Toronto
Post
by HormonX » Wed Feb 09, 2005 9:08 pm
Is there a function that would count number of words in a sentence ? If not what is the easiest way of doing that. Any help is welcome
Thank you.
Greg
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Feb 09, 2005 9:12 pm
djot
Forum Contributor
Posts: 313 Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:
Post
by djot » Wed Feb 09, 2005 9:14 pm
djot
Forum Contributor
Posts: 313 Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:
Post
by djot » Wed Feb 09, 2005 9:16 pm
-
*great, each time uselss to post...because meanwhile someONE else posted (feyd)
:)
djot
-
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Feb 09, 2005 9:17 pm
need to get faster fingers
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Feb 09, 2005 9:21 pm
from reading all the user comments it seems the accuracy of this function does not seem to be all that great... the best example I could find, being:
Code: Select all
<?php
//count words
$words_to_count = strip_tags($body);
$pattern = "/ї^(\w|\d|''|"|\.|\!|\?|;|,|\\|\/|\-\-|:|\&|@)]+/";
$words_to_count = preg_replace ($pattern, " ", $words_to_count);
$words_to_count = trim($words_to_count);
$total_words = count(explode(" ",$words_to_count));
?>
djot
Forum Contributor
Posts: 313 Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:
Post
by djot » Wed Feb 09, 2005 9:25 pm
-
need to get faster fingers
Not really. I read the forum topics via RSS feed, and I did reduce the refresh rate to 15min because I should do other things at the moment than serving the web and answering stupid questions...
djot
PS: Anyway, I won't give up
-
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Feb 09, 2005 9:47 pm
djot wrote: -
...and answering stupid questions...
-
booooooooooooooo
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Feb 09, 2005 10:18 pm
okay, that's enough. Locked.