|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-05-17 06:26 UTC] 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() PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 00:00:01 2025 UTC |
@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 )