note 26703 added to function.str-word-count
| From: | brettNOSPAM at olwm dot NO_SPAM dot com | Date: | Sat, 09 Nov 2002 18:06:14 +0000 |
| Subject: | note 26703 added to function.str-word-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39225@lists.php.net to get a copy of this message | ||
I tried to use your word counter and it wasn't accurate. This example may not be pretty, but
It proves accurate:
//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));
Hope I didn't miss any punctuation. ;-)
--
http://www.php.net/manual/en/function.str-word-count.php
http://master.php.net/manage/user-notes.php?action=edit+26703
http://master.php.net/manage/user-notes.php?action=delete+26703
http://master.php.net/manage/user-notes.php?action=reject+26703