note 69331 added to function.str-split
| From: | ference at super_delete_brose dot co dot uk | Date: | Thu, 31 Aug 2006 19:22:21 +0000 |
| Subject: | note 69331 added to function.str-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116564@lists.php.net to get a copy of this message | ||
If you are looking for a way to split multibyte strings then this may come in handy:
<?php
$text = "süpérbrôsé";
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;
}
$solo = mb_str_split($text);
$quintet = mb_str_split($text, 5);
print_r($solo);
print_r($quintet);
?>
Spits out:
Array
(
[0] => s
[1] => ü
[2] => p
[3] => é
[4] => r
[5] => b
[6] => r
[7] => ô
[8] => s
[9] => é
)
Array
(
[0] => süpér
[1] => brôsé
)
----
Server IP: 81.92.200.26
Probable Submitter: 87.196.97.213
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.str-split.php
Edit -- https://master.php.net/note/edit/69331
Del: integrated -- https://master.php.net/note/delete/69331/integrated
Del: useless -- https://master.php.net/note/delete/69331/useless
Del: bad code -- https://master.php.net/note/delete/69331/bad+code
Del: spam -- https://master.php.net/note/delete/69331/spam
Del: non-english -- https://master.php.net/note/delete/69331/non-english
Del: in docs -- https://master.php.net/note/delete/69331/in+docs
Del: other reasons-- https://master.php.net/note/delete/69331
Reject -- https://master.php.net/note/reject/69331
Search -- https://master.php.net/manage/user-notes.php