I'm a beginner in Curl and I'm having issues with the value that I get from curl_exec().
I'm connecting to a bank's server and want to get only the array from the server, but curl_exec() returns the whole string with the header and the array. How can I make it only send the array?
<?php
$url = 'https://the-url.com';
$auth = 'authentication key';
$method ='POST';
$grant = 'grant_type=client_credentials';
$crl = curl_init();
$headr = array();
$headr[] = 'Content-type: application/x-www-form-urlencoded';
$headr[] = 'Authorization: Basic '.$auth;
curl_setopt($crl, CURLOPT_URL,$url);
curl_setopt($crl, CURLOPT_HTTPHEADER,$headr);
curl_setopt($crl, CURLOPT_POST,true);
curl_setopt($crl, CURLOPT_HEADER, true);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($crl, CURLOPT_POSTFIELDS, $grant);
$rest = curl_exec($crl);
if ($rest === false)
{
print_r('Curl error: ' . curl_error($crl));
}
curl_close($crl);
$data = json_decode($rest, true);
echo $rest;
?>
this outputs
HTTP/2 200 a: x content-type: application/json content-length: 345 date: Tue, 21 Sep 2021 12:26:47 GMT strict-transport-security: max-age=63072000{array}
when I want it to output just {array} so I can use json_decode() on it