Reputation: 77
I connected to an e-commerce application via the following on the command line:
curl -u xxxxxx: https://xxxx/xxx
It returns something like this:
{ "charge_enabled": true,
"details_submitted": true,
"email": "[email protected]",
"id": "xxxx",
"statement_descriptor": "xxxx",
"xxxx": [ "USD" ]
}
When I change this to PHP to run this in a script, I also can retrieve the same info via the following:
$ch = curl_init('https://xxxx/xxxx');
$options = array(
CURLOPT_USERPWD=> $xxxxxx
);
curl_setopt_array($ch, $options);
$result2= curl_exec($ch);
However, when I try to retrieve the individual information like the email, I am unable to do so. I try to do so via json_decode
as follows:
$parsedresult = json_decode($result2,true);
$emailretrieve = $parsedresult["email"];
This returns only the single number 1
and not the email address.
Can anyone help and tell me what's wrong? I tried many things already posted here on StackOverflow and got none of them to work.
Upvotes: 0
Views: 202
Reputation: 4258
You should set the option CURLOPT_RETURNTRANSFER
(mentioned in http://php.net/curl_exec) to fetch the result. Right now, you only get "successful" or "failed" as result.
Upvotes: 2