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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:46:48+00:00 2026-06-15T10:46:48+00:00

I have a string variable named $message as below: * Time Stamp: 2012-12-03 16:36:04

  • 0

I have a string variable named $message as below:

        * Time Stamp: 2012-12-03 16:36:04 
        * Speed: 7 km/h 
        * Heading: 356 deg (N) 
        * Event ID: -48 
        * Event Desc: .Arrived at Inbound Receiving 
        * Event Value: -56
        * Event Value Type: 0

I then try to extract the event and timestamp values from the variable with the below code:

$event = null;
$lines = explode(PHP_EOL, $message);
foreach($lines as $line) {
  // skip empty lines
  if(strlen($line) == 0) {
    continue;
  }
  $tokens = explode(':', $line);
  // tokens[0] contains the key , e.g. Event Value
  // tokens[1]~[N] contains the value (where N is the number of pieces), e.g. -56
  // stitch token 1 ~ N
  $key = $tokens[0]; 
  unset($tokens[0]);
  $val = implode(': ', $tokens);
  // do your extra logic here, e.g. set $event variable to value
  if(strpos($key, 'Event Desc') > -1) {
    $event = $val;
  }
   if(strpos($key, 'Time Stamp') > -1) {
   $time = $val;
  }
}

This works great, only problem is that the returned values are:

.Arrived at Arrived at Inbound Receiving =

2012-12-03 16:36:04  =

Where does the equal sign come from and how can I remove it along with the trailing spaces?

my expected result would be:

.Arrived at Arrived at Inbound Receiving

and

2012-12-03 16:36:04

This is how it appears in the string variable.
Thanks as always.

  • 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-15T10:46:48+00:00Added an answer on June 15, 2026 at 10:46 am

    You can try

    preg_match_all("/ ([a-z ]+):([a-z0-9:\-. ]+)/i", $string,$match);
    $values = array_combine($match[1], $match[2]) ;
    
    echo $values['Time Stamp'] ,PHP_EOL ;
    echo $values['Speed'] ,PHP_EOL ;
    echo $values['Heading'] ,PHP_EOL ;
    echo $values['Event Desc'] ,PHP_EOL ;
    // .... etc
    

    Output

     2012-12-03 16:36:04 
     7 km
     356 deg 
     .Arrived at Inbound Receiving  
    

    Online Demo

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

Sidebar

Related Questions

For example, I have a string variable named str. This str has a value
I have a string variable containing time in hh:mm:ss format . How to convert
I have a superclass named Message with the field String msgType and a sub-class
I have a string containing the variable name. I want to get the value
I have a string variable in C# aka product_name, I want to filter like
I have the following string as a variable: var name1 = '001-C6AL7_deepgreen_C3AE7_tankhakinavy_FJAG7_blackredmulti_FBAE7_tanbrown.jpg'; Which is
I have a query string that contains a variable like this $field_name = 'features';
I have 4 string variables name, quest, favorite_color, speed that might be empty. I
I have a String variable (basically an English sentence with an unspecified number of
I have javascript string variable with var sttr=We prefer questions that can be answered

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.