I have an input of some products as "id" parameter, information about the purchase, status, and the user who's purchasing as you can see in this input example.
{"id":2694301,"state":3,"timeout":25,"date":"2014-04-27 00:32:37","date_timeout":"2014-04-27 01:00:02","user":"wolf_359","purchase":341.52},{"id":34017,"state":1,"timeout":10,"date":"2014-04-27 01:59:34","date_timeout":"2014-04-27 01:00:02","user":"mik10","purchase":217.90},{"id":12317,"state":2,"timeout":5,"date":"2014-04-27 03:51:31","date_timeout":"2014-04-27 01:00:02","user":"assemblyuser","purchase":1321.17};
What i'm trying is to get only one product, ordered with all the information, knowing the id. That means, for example, if I know that my Id is 34017, i just wanna show this row ignoring the others:
{"id":34017,"state":1,"timeout":10,"date":"2014-04-27 01:59:34","date_timeout":"2014-04-27 01:00:02","user":"mik10","purchase":217.90}
So the reason for what I'm asking help is that I don't know if there's any other possibility getting with substrings and explodes the data cause this looks very very complicated. This is what I've done:
preg_match_all('/{"id":2694017/', $page, $matches, PREG_OFFSET_CAPTURE);
$firstkey = $matches[0][0][1];
$page = substr($page, $firstkey, 210);
$values = explode('/:,', $page);
$value1 = $values[1];
$value2 = $values[2];
$value3 = $values[3];
$value4 = $values[4];
$value5 = $values[5];
$value6 = $values[6];
$value7 = $values[7];
In the first lane I obtain the position in the string the {
is. Then I cut with a substring the register plus a little bit more of the next preventing that the username could be very long. After, due to I know the registers I'm interested are in the next 7 colons, I just explode.