Re: Eval string to array

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

 



Jochem Maas wrote:

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....


For now, exactly like.
This is what I extracted from your example for it to work ->
$ret = str_replace("\n", '', curl_exec($this->curl_handle));
eval("\$arr = $ret;");
$arr1 = var_export($arr, true);
var_dump($arr);



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?


gotit


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


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


It was in the original email. Just not where you thought it would have been ;)

Thanks for your help.

--
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