note 113274 deleted from function.str-split by crell
| From: | crell@php.net | Date: | Wed, 29 Jun 2022 18:45:03 +0000 |
| Subject: | note 113274 deleted from function.str-split by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218697@lists.php.net to get a copy of this message | ||
Note Submitter: qeremy [atta] gmail [dotta] com
----
A new version of "str_split_unicode" prev.
<?php
function str_split_unicode($str, $length = 1) {
$tmp = preg_split('~~u', $str, -1, PREG_SPLIT_NO_EMPTY);
if ($length > 1) {
$chunks = array_chunk($tmp, $length);
foreach ($chunks as $i => $chunk) {
$chunks[$i] = join('', (array) $chunk);
}
$tmp = $chunks;
}
return $tmp;
}
?>
$s = 'Ãzgür Yazılım!'; // Open Source!
print_r(str_split_unicode($s));
print_r(str_split_unicode($s, 3));
Array
(
[0] => Ã
[1] => z
[2] => g
[3] => ü
[4] => r
[5] =>
[6] => Y
[7] => a
[8] => z
[9] => ı
[10] => l
[11] => ı
[12] => m
[13] => !
)
Array
(
[0] => Ãzg
[1] => ür
[2] => Yaz
[3] => ılı
[4] => m!
)