Re: Eval string to array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gerard Samuel wrote:
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', )

something LIKE? or exactly that?

anyway I don't have problems with this...

php -r '

eval("\$arr = array ( \"foo\" => \"bar\", );");
$arr1 = var_export($arr, true);
eval("\$arr2 = $arr1;");
var_dump($arr,$arr1,$arr2);

'

...took me a couple of
mins to figure out how you could be....


I would like to convert this to a real array. Im currently trying this -> $ret = curl_exec($this->curl_handle); $str = '$array = $ret;';

this is your problems. its to do with string interpolation. your exec() call is equivelant to

$array = $ret;

guess what that makes $array?
so it should be:

exec("\$array = $ret;");

which will replace the string $ret into the string to be
exec()'ed. alternatively:

exec('$array = '.$ret.';');

geddit?

eval($str);
var_dump($ret, $array);

next time paste the actual var_dump output, its easier. :-)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux