Req #67442 [NEW]: mbstring equivalent of `explode`
| From: | phpmpan at mpan dot pl | Date: | Sat, 14 Jun 2014 10:00:40 +0000 |
| Subject: | Req #67442 [NEW]: mbstring equivalent of `explode` | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-186190@lists.php.net to get a copy of this message | ||
From: phpmpan at mpan dot pl
Operating system:
PHP version: Irrelevant
Package: mbstring related
Bug Type: Feature/Change Request
Bug description:mbstring equivalent of
explode
Description:
------------
mbstring is missing explode equivalent.
⢠explode itself can't be used for the purpose, because it fails for
encodings that either have no autosynchronization property (like utf16)
or identical byte sequences are otherwise not uniquely mapped to
characters.
⢠mb_split requires regex as its argument - hence it is unsuitable
if the delimiter is not known during writing the code.
⢠mb_strpos + mb_substr tandem is very slow.
Test script:
---------------
function printHexString($string) {
foreach (str_split($string) as $character) {
echo dechex(ord($character)), ' ';
}
echo "\n";
}
mb_internal_encoding('utf-8'); // should match the actual encoding
$input = mb_convert_encoding('â¦â¡â¦â¡â¦â¡â¦abc',
'utf-16'); //
⦠is U+2126, ⡠is U+2621
$delimiter = mb_convert_encoding('â¦', 'utf-16'); // ⦠is U+2626
printHexString($input);
echo "\n";
$exploded = explode($delimiter, $input);
foreach ($exploded as $element) {
printHexString($element);
}
Expected result:
----------------
(assuming mb_explode instead explode)
21 26 26 21 21 26 26 21 21 26 26 21 26 26 0 61 0 62 0 63
21 26 26 21 21 26 26 21 21 26 26 21
0 61 0 62 0 63
Actual result:
--------------
21 26 26 21 21 26 26 21 21 26 26 21 26 26 0 61 0 62 0 63
21
21 21
21 21
21
0 61 0 62 0 63
--
Edit bug report at https://bugs.php.net/bug.php?id=67442&edit=1
--