Q:

PHP parsing table/array string

Hello Stack Overflow,
  This is my first post and I have a problem I need to parse this text and turn it into an array (its from a database).  
"TableToKeyValues"
{
    "inventory"
    {
        "slot2"
        {
            "amount"        "10"
            "item"      "wood_plank"
        }
        "slot1"
        {
            "amount"        "10"
            "item"      "metal"
        }
        "slot3"
        {
            "amount"        "10"
            "item"      "plastic"
        }
    }
}

Thanks rtm516.

A:

I worked out how to do it by formatting it into json useing str_replace alot of times.
$inv = preg_replace( "/\r|\n/", "", $inv);
$inv = str_replace('}', '},', $inv);
$inv = str_replace('"       "', '":"', $inv);
$inv = str_replace('"           "', '","', $inv);
$inv = str_replace('"       {', '":{', $inv);
$inv = str_replace('"   {', '":{', $inv);
$inv = str_replace('"{', '":{', $inv);
$inv = trim(preg_replace('/\t+/', '', $inv));
$inv = str_replace('},}', '}}', $inv);
$inv = str_replace('},},', '}}', $inv);
$inv = str_replace('"TableToKeyValues":', '', $inv);
$inv = json_decode($inv, true);

Edit: $inv is the value from the database.

