php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67442 mbstring equivalent of `explode`
Submitted: 2014-06-14 10:00 UTC Modified: 2020-11-03 18:14 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: phpmpan at mpan dot pl Assigned:
Status: Suspended Package: mbstring related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phpmpan at mpan dot pl
New email:
PHP Version: OS:

 

 [2014-06-14 10:00 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-11-03 18:14 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2020-11-03 18:14 UTC] cmb@php.net
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>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC