-4

I have this code inserted into the database: {"2":{"qty":1,"price":"10.00","room_id":{"1002":"1"}},"1":{"qty":2,"price":"35.00","room_id":["2"]},"3":{"qty":1,"price":"18.00","room_id":["1"]}}

I want to get the values FROM {"2":{"qty":1,"price":"10.00","room_id":{"1002":"1"}} TO "3":{"qty":1,"price":"18.00","room_id":["1"]}} and store each digit in a separate variable.

What would be the regular expression to match this?

2 Answers 2

11

what's the sytax i should use as regex please?

The answer is "none". You should not try to parse JSON using regexes. Use the json_decode() function instead.

Sign up to request clarification or add additional context in comments.

4 Comments

sorry, posted my answer as comment to your, it's fixed now
@PeterButkovic No problem, I removed my comment.
@C0deH4cker Been there, seen that :)
0

If you need to store json data in the database, why don't you use some noSQL one that does json internally?

I'd go for MongoDB. Or possibly any of these: Databases using JSON as storage/transport format

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.