If I have a String, containing the Javascript-Code for an array:
parent.data[0].c = [[10,'TESTVALUE',]];
with a lot of nested arrays in it. What is the best way to parse it with PHP. JSON is not an option due to the fact that the data is only available in the format above.
Thx!
-
can't the data be converted to json from js and then set to php ? then you can use json_decode();Poelinca Dorin– Poelinca Dorin2011年01月28日 11:32:30 +00:00Commented Jan 28, 2011 at 11:32
-
1possible duplicate of Parsing javascript arrays in PHPJohn Parker– John Parker2011年01月28日 11:33:33 +00:00Commented Jan 28, 2011 at 11:33
-
From what you've said, it's hard to see what the problem is with using JSON?Spudley– Spudley2011年01月28日 11:35:08 +00:00Commented Jan 28, 2011 at 11:35
2 Answers 2
If you remove the extra comma after testvalue, and change 'TESTVALUE' to "TESTVALUE" its valid json
I would probably do this with a recursive function that uses regular expression to find matching pairs of [ ] and build the array piece by piece. Probably requires a bit of trial and error not to miss any possible error sources when matching the regular expressions, but should not be too much work, due to recursivity.
Good luck.