Eval string to array

From: Date: Mon, 24 Jan 2005 17:57:49 +0000
Subject: Eval string to array
Groups: php.general 
Request: Send a blank email to php-general+get-207135@lists.php.net to get a copy of this message
Im trying to evaluate a string representation of the output of var_export(), as an array. To make a long story short, Im using curl to fetch another php page, that uses var_export to echo out php data structures. The fetched data via curl, is a string. Something like -> array ( 'foo' => 'bar', ) I would like to convert this to a real array. Im currently trying this -> $ret = curl_exec($this->curl_handle); $str = '$array = $ret;'; eval($str); var_dump($ret, $array); The resulting var_dump() shows that my eval'ed data is still a string. string(27) "array ( 'foo' => 'bar', )" string(27) "array ( 'foo' => 'bar', )" What should I be doing to get it as an array -> array(1) { ["foo"]=> string(3) "bar" } Thanks for your time.

« previous php.general (#207135) next »