Q:

Processing a string in PHP

I need a way of sorting a string I have in PHP, the string is formatted like the one below, but is much bigger. 
{ 1, 3, 1, 2, }, { 2, 3, 2, 1, }, { 3, 3, 2, 2, }, { 1, 2, 3, 1, },

What I would need it to do is turn each set of numbers that is in the brackets into an array.  So in this case there would be four arrays with four values in each array. 
The first array would look like the following:
array1[0] == 1
array1[1] == 3
array1[2] == 1
array1[3] == 2

How would I manage to do this? 

A:

$inbound = "{ 1, 3, 1, 2, }, { 2, 3, 2, 1, }, { 3, 3, 2, 2, }, { 1, 2, 3, 1, }";
$inbound = trim(preg_replace("/,\\s*}/i", "}", $inbound), " ,");
$inbound = str_replace("{", "[", $inbound);
$inbound = str_replace("}", "]", $inbound);

$array_of_arrays = json_decode('[' .  $inbound . ']'); 

A:

I can't comment (<50) but for Sean Bright, the problem with blank echo is that the json_decode doesn't like the trailing "," inside the [ ]..
edit : 
$inbound = str_replace( array( '{', ', }' ), array( '[', ']' ), $inbound );
fixes. 

A:

I think I would split by Close Brace, then split by comma.   That'd be the easiest way to write the code (possibly anyway, depending on your point of view), but not the most efficient in terms of complexity. 
The most efficient would just be to walk through the array, performing different actions when you find a comma or brace:
 arrayOfArrays = new Array()
 masterIndex = 0
 arrayOfArrays[masterIndex] = new Array()

 for char c in string
   if c == '}'
     masterIndex++
     arrayOfArrays[masterIndex] = new Array()
   else if c == ','
     append num to arrayOfArrays[masterIndex]
   else if c is whitespace
     noop
   else
     append c to num

