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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:15:12+00:00 2026-05-12T16:15:12+00:00

[Check My EDIT for better Explanation] I need some help with a very big

  • 0

[Check My EDIT for better Explanation]

I need some help with a very big string i have.

Its like this:

$big_string = "TinteiroID:1#TinteiroLABEL:HP CB335EE#TinteiroREF:CB335EE#TinteiroMARCA:HP#TinteiroGENERO:Tinteiro Preto Reciclado#TinteiroQUANTIDADE:23#FIMPROD#TinteiroID:4#TinteiroLABEL:HP 51633 M#TinteiroREF:51633 M#TinteiroMARCA:HP#TinteiroGENERO:Tinteiro Preto Reciclado#TinteiroQUANTIDADE:12#FIMPROD#";

It as no break lines, but it as white spaces.

If we take a good look this is, they are 2 strings like this:

$splited_string = "TinteiroID:1#TinteiroLABEL:HP CB335EE#TinteiroREF:CB335EE#TinteiroMARCA:HP#TinteiroGENERO:Tinteiro Preto Reciclado#TinteiroQUANTIDADE:23#FIMPROD#";

I think i need a preg_split to search in the $big_string for this:

TinteiroID:[only numbers]#TinteiroLABEL:[any character, except "#"]#TinteiroREF:[any character, except "#"]#TinteiroMARCA:[any character, except "#"]#TinteiroGENERO:[any character, except "#"]#TinteiroQUANTIDADE:[only numbers]#FIMPROD#

I have striped the $splited_string and inside the [ ] square brackets i quote which characters it can be there.

Instead of the [ ] square brackets it should be the RegExpression token for each type of characters that should be accepted. But i know little about this.

And then store each $splited_string in an array $array.

Can anybody give some clues how to accomplish this?

Thanks

EDIT:

I try to explain my logic.

I have this big string (with no break line):

TinteiroID:1#

TinteiroLABEL:HP CB335EE#

TinteiroREF:CB335EE#

TinteiroMARCA:HP#

TinteiroGENERO:Tinteiro Preto
Reciclado#

TinteiroQUANTIDADE:23#

FIMPROD#


TinteiroID:4#

TinteiroLABEL:HP 51633 M#

TinteiroREF:51633 M#

TinteiroMARCA:HP#

TinteiroGENERO:Tinteiro Preto
Reciclado#

TinteiroQUANTIDADE:12#

FIMPROD#

They can be split into 2 smaller string.

With the preg-split i wanted to assign each splited string that look alike these ones, but with different values:

TinteiroID:[only numbers]#

TinteiroLABEL:[any character, except "#"]#

TinteiroREF:[any character, except "#"]#

TinteiroMARCA:[any character, except "#"]#

TinteiroGENERO:[any character, except "#"]#

TinteiroQUANTIDADE:[only numbers]#

FIMPROD#

Then add each splited string to an array:

Array
(
    [0] => TinteiroID:1#TinteiroLABEL:HP CB335EE#TinteiroREF:CB335EE#TinteiroMARCA:HP#TinteiroGENERO:Tinteiro Preto Reciclado#TinteiroQUANTIDADE:23#FIMPROD#
    [1] => TinteiroID:4#TinteiroLABEL:HP 51633 M#TinteiroREF:51633 M#TinteiroMARCA:HP#TinteiroGENERO:Tinteiro Preto Reciclado#TinteiroQUANTIDADE:12#FIMPROD#
)

And then there will a for each loop to go into every object in the array. [0] [1] ...

Do another RegExpression to collect the values and do something with those values.

Yes its “messy” and takes much CPU but.. I don’t have a better ideia :S


EDIT:

Following the Advice:

I’ve did this code:

$big_string = "TinteiroID:1#TinteiroLABEL:HP CB335EE#TinteiroREF:CB335EE#TinteiroMARCA:HP#TinteiroGENERO:Tinteiro Preto Reciclado#TinteiroQUANTIDADE:23#FIMPROD#TinteiroID:4#TinteiroLABEL:HP 51633 M#TinteiroREF:51633 M#TinteiroMARCA:HP#TinteiroGENERO:Tinteiro Preto Reciclado#TinteiroQUANTIDADE:12#FIMPROD#";CB335EE#TinteiroREF:CB335EE#TinteiroMARCA:HP#TinteiroGENERO:Tinteiro Preto Reciclado#TinteiroQUANTIDADE:23#FIMPROD#";
$array = explode("FIMPROD#", $big_string);

print_r ($array);

It splits the big_string to the at the end of each “FIMPROD#” the Delimiter for each one.

Now i have go on the array, and for each value in it. Do something with it.

I will try that now… I will post something case i managed to do it or not.

  • 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-12T16:15:13+00:00Added an answer on May 12, 2026 at 4:15 pm

    why do you need regex here? why don’t you just split it twice?

    $num = 6;            # number of elements to in each splited_string
    $out = array();
    foreach ($explode('#', $big_string) as $str) {
        $tmp = explode(':', $str, 2);
        if (count($tmp) == 2) {
            $out[] = $tmp[1];
        }
    }
    $subs = intval(count($out) / $num);  # how many splited_strings in the big string
    for ($i=0; $i<$sub; $i+$num) {
        $each_id = array_slice($out, $i, $i+$num);  # contains six strings
    }
    

    here at each iteration, $each_id would contain six strings, you’d still need to convert first and last elements to integers.

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

Sidebar

Related Questions

No related questions found

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.