Req #67442 [Opn->Sus]: mbstring equivalent of `explode`
Edit report at https://bugs.php.net/bug.php?id=67442&edit=1
ID: 67442
Updated by: cmb@php.net
Reported by: phpmpan at mpan dot pl
Summary: mbstring equivalent of explode
-Status: Open
+Status: Suspended
Type: Feature/Change Request
Package: mbstring related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
This feature requires discussion for which this bug tracker is
unsuitable. If anybody is still interested in this, please
forward the request to the internals mailing list[1]. For the
time being, I'm suspending this ticket.
[1] <https://www.php.net/mailing-lists.php#internals>
Previous Comments:
------------------------------------------------------------------------
[2014-06-14 10:00:39] phpmpan at mpan dot pl
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 this bug report at https://bugs.php.net/bug.php?id=67442&edit=1
Thread (2 messages)