note 26703 modified in function.str-word-count by aidan

From: Date: Sat, 26 Jun 2004 06:18:54 +0000
Subject: note 26703 modified in function.str-word-count by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71724@lists.php.net to get a copy of this message
This example may not be pretty, but It proves accurate: <?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)); ?> Hope I didn't miss any punctuation. ;-) --was-- 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://php.net/manual/en/function.str-word-count.php

« previous php.notes (#71724) next »