note 85592 added to function.str-word-count
| From: | om+www dot php dot net at miakinen dot net | Date: | Sun, 07 Sep 2008 20:23:46 +0000 |
| Subject: | note 85592 added to function.str-word-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144229@lists.php.net to get a copy of this message | ||
The previous function str_word_count_utf8 implemented only the first parameter, $string. Here is an
implementation which also supports the second parameter, $format. The $charlist is not supported,
though it could be possible to give the possibility to change the MASK.
<?php
define("WORD_COUNT_MASK", "/\p{L}[\p{L}\p{Mn}\p{Pd}'\x{2019}]*/u");
function str_word_count_utf8($string, $format = 0)
{
switch ($format) {
case 1:
preg_match_all(WORD_COUNT_MASK, $string, $matches);
return $matches[0];
case 2:
preg_match_all(WORD_COUNT_MASK, $string, $matches, PREG_OFFSET_CAPTURE);
$result = array();
foreach ($matches[0] as $match) {
$result[$match[1]] = $match[0];
}
return $result;
}
return preg_match_all(WORD_COUNT_MASK, $string, $matches);
}
?>
Note that in the case $format=2 the numeric positions are expressed in octets, not in characters.
----
Server IP: 208.69.120.35
Probable Submitter: 87.231.120.194
----
Manual Page -- http://www.php.net/manual/en/function.str-word-count.php
Edit -- https://master.php.net/note/edit/85592
Del: integrated -- https://master.php.net/note/delete/85592/integrated
Del: useless -- https://master.php.net/note/delete/85592/useless
Del: bad code -- https://master.php.net/note/delete/85592/bad+code
Del: spam -- https://master.php.net/note/delete/85592/spam
Del: non-english -- https://master.php.net/note/delete/85592/non-english
Del: in docs -- https://master.php.net/note/delete/85592/in+docs
Del: other reasons-- https://master.php.net/note/delete/85592
Reject -- https://master.php.net/note/reject/85592
Search -- https://master.php.net/manage/user-notes.php