note 107363 added to function.str-word-count
| From: | cito at wikatu dot com | Date: | Fri, 03 Feb 2012 21:29:57 +0000 |
| Subject: | note 107363 added to function.str-word-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185842@lists.php.net to get a copy of this message | ||
<?php
/***
* This simple utf-8 word count function (it only counts)
* is a bit faster then the one with preg_match_all
* about 10x slower then the built-in str_word_count
*
* If you need the hyphen or other code points as word-characters
* just put them into the [brackets] like [^\p{L}\p{N}\'\-]
* If the pattern contains utf-8, utf8_encode() the pattern,
* as it is expected to be valid utf-8 (using the u modifier).
**/
// Jonny 5's simple word splitter
function str_word_count_utf8($str) {
return count(preg_split('~[^\p{L}\p{N}\']+~u',$str));
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 84.145.39.125
----
Manual Page -- http://www.php.net/manual/en/function.str-word-count.php
Edit -- https://master.php.net/note/edit/107363
Del: integrated -- https://master.php.net/note/delete/107363/integrated
Del: useless -- https://master.php.net/note/delete/107363/useless
Del: bad code -- https://master.php.net/note/delete/107363/bad+code
Del: spam -- https://master.php.net/note/delete/107363/spam
Del: non-english -- https://master.php.net/note/delete/107363/non-english
Del: in docs -- https://master.php.net/note/delete/107363/in+docs
Del: other reasons-- https://master.php.net/note/delete/107363
Reject -- https://master.php.net/note/reject/107363
Search -- https://master.php.net/manage/user-notes.php