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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:19:37+00:00 2026-05-18T08:19:37+00:00

I am parsing a string in PHP that has the following pattern VARIABLE Key1

  • 0

I am parsing a string in PHP that has the following pattern

VARIABLE Key1 Value1 Key2 Value2 Key3 Value3 ...

similar to:

JOBGRADE 'P' 'Parttime Employee' 'C' 'Customer Support'

OR

SOMEVARIABLE 1 "Value1" 2 'Value2'

This line starts with an unquoted string and can have single or double quoted strings and/or numbers. It can have one to multiple key value pairs.

I need to split the string in 2 ways:

The first to get the unquoted string that is not numeric.

The second to extract the numeric value and/or quoted strings – can be single or dobule

Thus I need

  1. JOBGRADE
  2. P:Parttime Employee
  3. C:Customer Support

OR

  1. SOMEVARIABLE
  2. 1:Value1
  3. 2:Value2

My Thoughts:

I thought about splitting the string and iterating through it to test:

for 1: If value is not numeric and not quoted it is the variable name

for 2+: Not sure the easy way to do this because I must detect the difference between the keys and values:

Question:

How can I distinguish between the key/value?

  • 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-18T08:19:37+00:00Added an answer on May 18, 2026 at 8:19 am

    Treat it as CSV, and iterate over it to divide it up. The variable is [0], keys are odd starting from [1], values even from [2].

    var_dump(str_getcsv("JOBGRADE 'P' 'Parttime Employee' 'C' 'Customer Support'",
      ' ', "'"));
    
    array(5) {
      [0]=>
      string(8) "JOBGRADE"
      [1]=>
      string(1) "P"
      [2]=>
      string(17) "Parttime Employee"
      [3]=>
      string(1) "C"
      [4]=>
      string(16) "Customer Support"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that the choice to use string parsing vs. regular expressions comes up
I have a php script that truncates a string at 41 bytes. I call
I'm looking at parsing a delimited string, something on the order of a,b,c But
I'm doing simple string input parsing and I am in need of a string
I'm parsing text from a file and storing it in a string. The problem
Can someone provide a regular expression for parsing name/value pairs from a string? The
I have a simple text that is being parsed with PHP. In that text,
I'm developing an application that detects Source-based games running on the LAN. Following up
I'm having some trouble parsing malformed XML in PHP. In particular I'm querying a
I am parsing an xml file using php simplexml_load_file() and then inserting the desired

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.