I've been working on a PHP project using cURL to access external API. Even though connecting via API is successfully done, one subtle thing bothers me... That is, "return values of curl_exec($curl) are dumped out automatically".
Here's my codes.
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_HTTPHEADER, ["Content-Type: application/x-www-form-urlencoded"]);
curl_setopt($curl, CURLOPT_URL, 'http://...');
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($some_post_data));
$result = curl_exec($curl);
curl_close($curl);
That's all.
I didn't write "var_dump" or "print_r" or anything to output the result. Nevertheless, there's always dumped result values on the display... more precisely, the dumping occurs at the line
$result = curl_exec($curl);
Does anyone know what's happening?
Set CURLOPT_RETURNTRANSFER to TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);