note 104837 deleted from function.str-word-count by danbrown

From: Date: Fri, 31 Aug 2012 16:24:23 +0000
Subject: note 104837 deleted from function.str-word-count by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190357@lists.php.net to get a copy of this message
Note Submitter: Stano110 at azet dot sk ---- This function count words, is quick and works well with utf-8: function count_words($string) { //$string = htmlspecialchars_decode(strip_tags($string)); // optional $t = array(' '=>1, '_'=>1, "\x20", "\xA0", "\x0A", "\x0D", "\x09", "\x0B", '='=>1, '+'=>1, '-'=>1, '*'=>1, '/'=>1, '\\'=>1, ','=>1, '.'=>1, ';'=>1, ':'=>1, '"'=>1, '\''=>1, '['=>1, ']'=>1, '{'=>1, '}'=>1, '('=>1, ')'=>1, '<'=>1, '>'=>1, '&'=>1, '%'=>1, '$'=>1, '@'=>1, '#'=>1, '^'=>1, '!'=>1, '?'=>1); // separators $count= isset($t[$string[0]])? 0:1; for ($i=1;$i<strlen($string);$i++) if (isset($t[$string[$i-1]]) && !isset($t[$string[$i]])) // if new word starts $count++; return $count; }

« previous php.notes (#190357) next »