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 8646731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:53:23+00:00 2026-06-12T12:53:23+00:00

This question is different to Split, a string, at every nth position, with PHP

  • 0

This question is different to Split, a string, at every nth position, with PHP, in that I want to split a string like the following:

foo|foo|foo|foo|foo|foo

Into this (every 2nd |):

array (3) {
  0 => 'foo|foo',
  1 => 'foo|foo',
  2 => 'foo|foo'
}

So, basically, I want a function similar to explode() (I really doubt that what I’m asking will be built-in), but which ‘explodes’ at every nth appearance of a certain string.

How is this possible?

  • 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-06-12T12:53:24+00:00Added an answer on June 12, 2026 at 12:53 pm

    You can use explode + array_chunk + array_map + implode

    $string = "foo|foo|foo|foo|foo|foo";
    $array = stringSplit($string,"|",2);
    var_dump($array);
    

    Output

    array
      0 => string 'foo|foo' (length=7)
      1 => string 'foo|foo' (length=7)
      2 => string 'foo|foo' (length=7)
    

    Function used

    function stringSplit($string, $search, $chunck) {
        return array_map(function($var)use($search){return implode($search, $var); },array_chunk(explode($search, $string),$chunck));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a different question ( How to split a number into individual digits? ),
I asked a question about different testing frameworks yesterday. This question can be found
This question is a little different from others of a similar title. I am
This question has been asked in various forms in a number of different forums,
This is related to this question but with a different take. In Ubuntu, I
This is similar to (but different from) this question . Here is some simple
I'm re-asking this question but with a different framework this time. I have two
I know this question has been done but I have a slightly different twist
I believe this question might have been previously attempted in 2006 on a different
(Similar in spirit to but different in practice from this question .) 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.