how to retrieve substring from string having variable length of character in php?

Posted by user187580 on Stack Overflow See other posts from Stack Overflow or by user187580
Published on 2010-04-09T09:57:10Z Indexed on 2010/04/09 10:03 UTC
Read the original article Hit count: 113

Filed under:
|

Hello

I have some data in the format of

C222 = 50
C1234P687 = 'some text'
C123YYY = 'text'
C444 = 89
C345 = 3
C122P687 = 'some text'
C122YYY = 'text'
....
....

so basically 3 different forms

  1. "C" number = value, example - C444 = 89
  2. "C" number "P" number = value, example - C123P687 = 'some text'
  3. "C" number "YYY" = value

Only number is of variable length on the left side of (=) sign. Values vary.

I want to store the data in db as

INSERT INTO datatable 
    c_id = "number after C"
    p_id = "number after P" // if it exists for a line of data
    value = 'value'
    yyy = 'value'

Any ideas how to retrieve these numbers?

Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about string-manipulation