Reputation: 2100
I'm not talking about JSON. I've got a program with the input being a javascript data structure in string format, something like this:
$string = "
var records = new Array();
records[0] = new Record('data1','data2',data3');
records[1] = new Record('data1','data2',data3');
records[2] = new Record('data1','data2',data3');";
Is there an easy way/library to turn this into a PHP data structure? The only way I can think of is to use str_replace to manipulate the string in order to turn it into JSON and then use json_decode.
Just wondering if there's a better way to do it.
Upvotes: 0
Views: 414
Reputation: 11029
You can post it to PHP as a string delimited by some character:
$phpArray = explode(",",$postValue);
This is not a better way just another way to do it. But not without potential problems. You have to ensure the delimiter you use is not used in the text and validate.
Upvotes: 0