note 116385 deleted from function.str-split by salathe
| From: | salathe@php.net | Date: | Fri, 02 Jan 2015 11:24:26 +0000 |
| Subject: | note 116385 deleted from function.str-split by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-201309@lists.php.net to get a copy of this message | ||
Note Submitter: qeremy ! gmail ! com
----
A proper unicode string split (v2);
<?php
function str_split_unicode($str, $len = 1) {
$tmp = preg_split('~~u', $str, -1, PREG_SPLIT_NO_EMPTY);
if ($len > 1) {
$tmp = array_map('join', array_chunk($tmp, $len));
}
return $tmp;
}
?>
$s = 'Ilık süt'; // Mild milk
print_r(str_split($s, 3));
print_r(str_split_unicode($s, 3));
Array
(
[0] => Il�
[1] => �k
[2] => sü
[3] => t
)
Array
(
[0] => Ilı
[1] => k s
[2] => üt
)