php - How to turn a string into and array -


i have string saved in database:

'array\n (\n    [id] => xxx111\n    [amount] => 2000\n    [currency] => usd\n    [created] => xxx222\n    [object] => refund\n    [balance_transaction] => xxx333\n    [charge] => xxx444\n    [receipt_number] => xxx555\n    [reason] => requested_by_customer\n )' 

and need parse how , array(). \n don't appear in db, when retrieve them , check value in xdebug \n show up.

i've tried using eval() so:

eval('$my_array = ' . $string_from_db . ';'); 

but doesn't work because of []s indexes instead of ""s. tried string replaces switch them , add commas regex-fu isn't great.

any appreciated.

messy , ugly , should trick

$array(); $tmparray=explode("\n",$str); foreach($tmparray $row){    if(strpos($row,'>')!==false){      $tab2=explode(">",$row);      $array[trim(substr(trim($tab2[0]),1,-3))]=trim($tab2[1]);    }  } 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo