Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6670039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:13:18+00:00 2026-05-26T03:13:18+00:00

I needed to split a string by different delimiters. So i found & used

  • 0

I needed to split a string by different delimiters. So i found & used this code:

function explodeX($delimiters,$string)
{
    $return_array = Array($string);
    $d_count = 0;
    while (isset($delimiters[$d_count]))
    {
        $new_return_array = Array();
        foreach($return_array as $el_to_split)
        {
            $put_in_new_return_array = explode($delimiters[$d_count],$el_to_split);
            foreach($put_in_new_return_array as $substr)
            {
                $new_return_array[] = $substr;
            }
        }
        $return_array = $new_return_array;
        $d_count++;
    }
    return $return_array;
} 

It worked fine, but now, I need to reverse it and find, which delimeter it actually used.
I used this kind of line:

$val=explodeX(array("+","-","*","/"), $input);

Now, I need to return the right delimiter back in.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:13:18+00:00Added an answer on May 26, 2026 at 3:13 am

    All the delimeters you set in $delimiters are used, as shown in this line:

    while (isset($delimiters[$d_count]))
    

    $d_count is incremented at the bottom of the loop, $d_count++, and $return_array is returned after it loops through all your delimiters, seperating as much from $string as you have specified.

    To put the correct delimiter back in the position it was in before, you can’t, unless you modify what information you return in $return_array. Something like this is what you’re looking for:

    $return_array[] = $new_return_array;
    $delim = $delimiters[$d_count];
    $return_array['delim'] = new Array();
    $return_array['delim'][$delim][] = $new_return_array;
    $d_count++;
    

    This will store the words seperated by each delimiter in a child array under the delim index of your returned result. Then all you would need to do to implode them back is something like this:

    $string2 = '';
    foreach ( $return_array as $delim => $word )
    {
        // not sure how to reverse your function at this moment, will get back with this part...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I needed to split a string of numerous words into an array which
I needed some simple string encryption, so I wrote the following code (with a
I need to split a string based on some character array of separators and
I need a function in Excel VBA that will split a string with a
I needed to find all the files that contained a specific string pattern. The
I have a static method like this public static string DoSomethingToString(string UntrustedString) { //parse
I have the following string 3/4Ton. I want to split it as --> word[1]
I had a scanned multipage TIFF image and needed to split each page out
I just had a use case where I needed to split a list into
I have a string as under =[Book1]Sheet1!$F$13 The needed output being Book1 Is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.