Page 1 of 1

word counter

Posted: Wed Feb 09, 2005 9:08 pm
by HormonX
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

Posted: Wed Feb 09, 2005 9:12 pm
by feyd

Posted: Wed Feb 09, 2005 9:14 pm
by djot
-
function str_word_count: --> http://www.php.net/manual/en/function.s ... -count.php

djot
-

Posted: Wed Feb 09, 2005 9:16 pm
by djot
-
*great, each time uselss to post...because meanwhile someONE else posted (feyd)

:)

djot
-

Posted: Wed Feb 09, 2005 9:17 pm
by feyd
need to get faster fingers :mrgreen:

Posted: Wed Feb 09, 2005 9:21 pm
by John Cartwright
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 = "/&#1111;^(\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)); 
?>

Posted: Wed Feb 09, 2005 9:25 pm
by djot
-
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 :)
-

Posted: Wed Feb 09, 2005 9:47 pm
by John Cartwright
djot wrote:-
...and answering stupid questions...
-
booooooooooooooo :evil:

Posted: Wed Feb 09, 2005 10:03 pm
by djot
-
boooooooooooooooooooooooo
Yes booo.


And an additionally boooooooooooooooooo from me for people that are toooooo lazy to even try to find the anwer themselves at

php.net
http://www.php.net/manual/en/ref.strings.php
(not too hard to find and to read)

or even google.
http://www.google.com/search?q=word+count+function+php
(4th position)


djot
-

Posted: Wed Feb 09, 2005 10:18 pm
by feyd
okay, that's enough. Locked.