note 125451 added to function.str-word-count

From: Date: Thu, 22 Oct 2020 08:16:42 +0000
Subject: note 125451 added to function.str-word-count
Groups: php.notes 
Request: Send a blank email to php-notes+get-215628@lists.php.net to get a copy of this message
preg_match_all based function to mimic str_word_count behavior: <?php function mb_str_word_count($str, $format = 2, $charlist = '') { if ($format < 0 || $format > 2) { throw new InvalidArgumentException('Argument #2 ($format) must be a valid format value'); } $count = preg_match_all('#[\p{L}\p{N}][\p{L}\p{N}\'' . $charlist . ']*#u', $str, $matches, $format === 2 ? PREG_OFFSET_CAPTURE : PREG_PATTERN_ORDER); if ($format === 0) { return $count; } $matches = $matches[0] ?? []; if ($format === 2) { $result = []; foreach ($matches as $match) { $result[$match[1]] = $match[0]; } return $result; } return $matches; } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.174 (proxied: 194.44.226.174) ---- Manual Page -- http://php.net/manual/en/function.str-word-count.php Edit -- https://master.php.net/note/edit/125451 Del: integrated -- https://master.php.net/note/delete/125451/integrated Del: useless -- https://master.php.net/note/delete/125451/useless Del: bad code -- https://master.php.net/note/delete/125451/bad+code Del: spam -- https://master.php.net/note/delete/125451/spam Del: non-english -- https://master.php.net/note/delete/125451/non-english Del: in docs -- https://master.php.net/note/delete/125451/in+docs Del: other reasons-- https://master.php.net/note/delete/125451 Reject -- https://master.php.net/note/reject/125451 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#215628) next »