note 104837 added to function.str-word-count

From: Date: Sun, 10 Jul 2011 12:05:05 +0000
Subject: note 104837 added to function.str-word-count
Groups: php.notes 
Request: Send a blank email to php-notes+get-181402@lists.php.net to get a copy of this message
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; } ---- Server IP: 69.147.83.197 Probable Submitter: 80.87.209.10 ---- Manual Page -- http://www.php.net/manual/en/function.str-word-count.php Edit -- https://master.php.net/note/edit/104837 Del: integrated -- https://master.php.net/note/delete/104837/integrated Del: useless -- https://master.php.net/note/delete/104837/useless Del: bad code -- https://master.php.net/note/delete/104837/bad+code Del: spam -- https://master.php.net/note/delete/104837/spam Del: non-english -- https://master.php.net/note/delete/104837/non-english Del: in docs -- https://master.php.net/note/delete/104837/in+docs Del: other reasons-- https://master.php.net/note/delete/104837 Reject -- https://master.php.net/note/reject/104837 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181402) next »