|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67659 Support array of delimiters in explode()
Submitted: 2014-07-21 12:07 UTC Modified: 2020-11-03 18:03 UTC
From: arcadius at mail dot ru Assigned:
Status: Suspended Package: Strings related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: arcadius at mail dot ru
New email:
PHP Version: OS:


 [2014-07-21 12:07 UTC] arcadius at mail dot ru
Let give several delimiters as array to explode() function to explode input string by any of them. Delimiters listed earlier have higher priority:
array(',', ', ') // Wrong!
array(', ', ',') // Right.

Test script:
function dump_path($path)
	$arr = explode( array('\\', '/'), $path );

function dump_name($name)
	$arr = explode( array(' ', '.'), $name );
dump_name('Albert Einstein');


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-21 12:10 UTC] arcadius at mail dot ru
-Summary: Use array of delimiters in explode() +Summary: Support array of delimiters in explode()
 [2014-07-21 12:10 UTC] arcadius at mail dot ru
Changed title of the request.
 [2014-07-21 12:29 UTC] anon at anon dot anon
You can already do that (and a hell a lot of more) with regex. For the specific examples you gave:

    1. $arr = preg_split('/\/|\\\\/', $path);

    2. $arr = preg_split('/ |\./', $name );

In general:

    function explode_multi($delimiters, $string, $limit = -1) {
        $pattern = '/';
        foreach ($delimiters as $d) $pattern .= preg_quote($d, '/') . '|';
        $pattern[strlen($pattern) - 1] = '/';
        return preg_split($pattern, $string, $limit);
 [2018-02-28 20:13 UTC]
-Package: Unknown/Other Function +Package: Strings related
 [2020-11-03 18:03 UTC]
-Status: Open +Status: Suspended
 [2020-11-03 18:03 UTC]
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] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Oct 17 16:03:34 2021 UTC