Req #62051 [Com]: missing function: mb_str_split()

From: Date: Thu, 04 Jul 2013 15:05:25 +0000
Subject: Req #62051 [Com]: missing function: mb_str_split()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-180072@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62051&edit=1 ID: 62051 Comment by: jan dot bouvrie at gmail dot com Reported by: info at javabar dot de Summary: missing function: mb_str_split() Status: Wont fix Type: Feature/Change Request Package: mbstring related Operating System: all PHP Version: Irrelevant Assigned To: moriyoshi Block user comment: N Private report: N New Comment: @moriyoshi array str_split (string $string[, int $split_length = 1 ]) Converts a string to an array. array mb_split (string $pattern, string $string [, int $limit = -1 ]) Split a multibyte string using regular expression pattern and returns the result as an array. Performance-wise, I wouldn't say mb_split (using a regular expression) is the same as str_split? Also, I'm curious how to call mb_split with a proper regexp so that it simulates str_split? Example: <?php function mb_str_split($str, $length = 1) { if ($length < 1) return FALSE; $result = array(); for ($i = 0; $i < mb_strlen($str); $i += $length) { $result[] = mb_substr($str, $i, $length); } return $result; } mb_internal_encoding('UTF-8'); mb_regex_encoding('UTF-8'); $test='әӘ火车票abc'; print_r(preg_split('/(?<!^)(?!$)/u', $test)); print_r(mb_str_split($test)); print_r(mb_split('/./',$test)); ?> outputs: Array ( [0] => ә [1] => Ә [2] => 火 [3] => 车 [4] => 票 [5] => a [6] => b [7] => c ) Array ( [0] => ә [1] => Ә [2] => 火 [3] => 车 [4] => 票 [5] => a [6] => b [7] => c ) Array ( [0] => әӘ火车票abc ) Previous Comments: ------------------------------------------------------------------------ [2012-06-02 06:10:48] moriyoshi@php.net I have the impression that mb_split() pretty much does the expected work, unless we really want a counterpart of every byte-wise string function in mbstring... ------------------------------------------------------------------------ [2012-05-19 06:48:19] laruence@php.net moriyoshi sama, what do you think about this FR? thanks ------------------------------------------------------------------------ [2012-05-17 06:26:25] info at javabar dot de Description: ------------ The multibyte version of str_split(), which splits a string into an array of chunks, does not seem to be implementated yet. The name should be: mb_str_split() ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62051&edit=1

« previous php.bugs (#180072) next »