Get usable array from a curl response, which is formatted as a php array
Posted
by Mint
on Stack Overflow
See other posts from Stack Overflow
or by Mint
Published on 2010-04-04T13:39:14Z
Indexed on
2010/04/04
13:43 UTC
Read the original article
Hit count: 296
$ch = curl_init("url");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "test");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$outputArray = curl_exec($ch);
Then $outputArray will contain:
Array
(
[0] => Array
(
[r1] => test response
[r2] => 4
[r3] => 32
)
)
So I would think PHP can see that it's an array and treat it as such, but when I do something like
echo $outputCode[0][r_title]."\n";
it gives an error:
PHP Fatal error: Cannot use string offset as an array in /www/test.php on line 75
(line 75 being the echo one just above)
What am I doing wrong?
© Stack Overflow or respective owner