note 111177 added to function.str-word-count

From: Date: Tue, 22 Jan 2013 20:46:16 +0000
Subject: note 111177 added to function.str-word-count
Groups: php.notes 
Request: Send a blank email to php-notes+get-193350@lists.php.net to get a copy of this message
A simple approach to unicode words count; <?php function str_word_count_unicode($str, $format = 0) { $words = preg_split('~[\s0-9_]|[^\w]~u', $str, -1, PREG_SPLIT_NO_EMPTY); return ($format === 0) ? count($words) : $words; } ?> $str = 'äb"c äb3c a_b!'; echo str_word_count($str); // 6 echo str_word_count_unicode($str); // 6 print_r(str_word_count($str, 1)); print_r(str_word_count_unicode($str, 1)); Array ( [0] => b [1] => c [2] => b [3] => c [4] => a [5] => b ) Array ( [0] => äb [1] => c [2] => äb [3] => c [4] => a [5] => b ) ---- Server IP: 95.130.168.26 Probable Submitter: 88.253.76.215 ---- Manual Page -- http://php.net/manual/en/function.str-word-count.php Edit -- https://master.php.net/note/edit/111177 Del: integrated -- https://master.php.net/note/delete/111177/integrated Del: useless -- https://master.php.net/note/delete/111177/useless Del: bad code -- https://master.php.net/note/delete/111177/bad+code Del: spam -- https://master.php.net/note/delete/111177/spam Del: non-english -- https://master.php.net/note/delete/111177/non-english Del: in docs -- https://master.php.net/note/delete/111177/in+docs Del: other reasons-- https://master.php.net/note/delete/111177 Reject -- https://master.php.net/note/reject/111177 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193350) next »