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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:32:23+00:00 2026-05-28T05:32:23+00:00

I have the following problem: I have a Text with the e.g. the following

  • 0

I have the following problem:

I have a Text with the e.g. the following Format:

min: 34.0 max: 79.0383 lifetime: 17% code:iweo7373333

It’s not a fixed text Type, means min can also be -7.94884444 or so. How can i extract the parts in e.g. an array like

$result['min'] = 34.0;
$result['max'] = 79.0383
and so on...

I did it at the moment with replacing spaces, then replace “min:” with nothing, “max:”, “lifetime:”, … with “,” and then an explode… The main Problem is that sometimes other variables are between min, max, …. so the positions do not hold the correct values.

Also – i think – it’s not a really good coding style or? Is this possible with regex or preg_replace?

Thanks,
Sascha

  • 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-28T05:32:23+00:00Added an answer on May 28, 2026 at 5:32 am

    Also – i think – it’s not a really good coding style or?

    There is no need to be authoritative about it. It depends on your purposes. I would personally opt for JSON in this case. XML can be an overkill most of the times.
    The only advantage I see in keeping that format you proposed is that it has no need for complex syntax using {}()[];, (and it seems you don’t need nesting).

    This regex will match all the parameter:value combinations from your string, being very tolerant with use of whitespace on values:

    (?<=^| )[A-Za-z-_]{0,}:[.,\$\-\+\s%\w]{0,}(?<=\s|\Z|^)

    So in PHP:

    $string = "simple:I like to exchange data a-css-like-parameter: 34px CamelCasedParameter: -79.0383 underlined_parameter: 17%";
    
    preg_match_all('/(?<=^| )[A-Za-z-_]{0,}:[.,\$\-\+\s%\w]{0,}(?<=\s|\Z|^)/', $string, $matches);
    
    $parameters = array();
    foreach($matches[0] as $parameter){
        $exploded = explode(':', $parameter);
        $parameters[$exploded[0]] = trim($exploded[1]);
    }
    
    print_r($parameters);
    

    Output:

    > Array
    > (
    >    [simple] => I like to exchange data
    >    [a-css-like-parameter] => 34px
    >    [CamelCasedParameter] => -79.0383
    >    [underlined_parameter] => 17%
    > )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem: I got a view with two text fields and
I have the following problem with Tikz/Latex: I have some nodes that contain text.
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
I have some text files with the following format: 000423|东阿阿胶| 300|1|0.15000| | 000425|徐工机械| 600|1|0.15000|
I have a small problem in my code. I have the following code: import
I have following problem: I have built a tabbar application with 4 tabs. I
I have the following problem: I have a form in site/banen (currently local running
I have the following problem. I have three classes, A, B and C. A
I have the following problem: I implemented a managed mobile application for Windows Mobile
I have the following problem that the standard library doesn't solve well, and I'm

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.