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

  • SEARCH
  • Home
  • 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 9084263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:57:29+00:00 2026-06-16T20:57:29+00:00

Possible Duplicate: Splitting string array based upon digits in php? I have a set

  • 0

Possible Duplicate:
Splitting string array based upon digits in php?

I have a set of data that’s all in one big chunk of text. It looks similar to the following;

01/02 10:45:01 test data 01/03 11:52:09 test data 01/04 18:63:05 test data 01/04 21:12:09 test data 01/04 13:10:07 test data 01/05 07:08:09 test data 01/05 10:07:08 test data 01/05 08:00:09 test data 01/06 11:01:09 test data

I’m trying to simply make this readable (see below for example), but the only thing on each of the lines that’s remotely similar is that the start follows a 00/00 pattern.

01/02 10:45:01 test data 
01/03 11:52:09 test data 
01/04 18:63:05 test data 
01/04 21:12:09 test data 
01/04 13:10:07 test data 
01/05 07:08:09 test data 
01/05 10:07:08 test data 
01/05 08:00:09 test data 
01/06 11:01:09 test data 

I’ve gotten as far as splitting it out by matching it to a regex pattern;

$split = preg_split("/\d+\\/\d+ /", $contents, -1, PREG_SPLIT_NO_EMPTY);

And this outputs;

Array ( [0] => 
        [1] => 10:45:01 test data 
        [2] => 11:52:09 test data 
        [3] => 18:63:05 test data 
        [4] => 18:63:05 test data 
        ...and so on

But as you can see the problem is that preg_split isn’t keeping the delimeter. I’ve tried changing the preg_split to;

$split = preg_split("/\d+\\/\d+ /", $contents, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE

However this returns the same as above, with no 00/00 at the start of the line.

Have I done something wrong or is their a better way of achieving this?

  • 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-16T20:57:31+00:00Added an answer on June 16, 2026 at 8:57 pm

    You can tell preg_split() to split at any point in the string which is followed by digits-slash-digits by using a lookahead assertion.

    $result = preg_split('#(?=\d+/\d+)#', $contents, -1, PREG_SPLIT_NO_EMPTY);
    

    The PREG_SPLIT_NO_EMPTY flag is used because the very start of the string is also a point where there are three digits, so an empty split happens here. We could alter the regex to not split at the very start of the string but that would make it a little more difficult to understand at-a-glance, whereas the flag is very clear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Splitting a string in C++ I have this vector function from one
Possible Duplicate: Splitting a string in C++ In PHP, the explode() function will take
Possible Duplicate: splitting a string i have a string which looks like this: http://pastebin.com/m5508ff19
Possible Duplicate: Splitting a string in C++ Im trying to create a function that
Possible Duplicate: Does every Core Data Relationship have to have an Inverse? I have
Possible Duplicate: Splitting a string in C++ I'm working on an assignment for my
Possible Duplicate: Python splitting strings and jumbling the middle I have a program in
Possible Duplicate: Splitting one column into two columns in SQL Server CE I am
Possible Duplicate: Turning long fixed number to array Ruby Well, I have to iterate
Possible Duplicate: Evaluate C# string with math operators So lets say I have a

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.