curl_exec printing results when I don't want to
I开发者_如何学Python am using the following code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 12);
$result = curl_exec($ch);
curl_close ($ch);
However it's printing the results straight away. Is it possible to put the JSON result into a variable so I can print it out when I want to?
Set CURLOPT_RETURNTRANSFER
option:
// ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
Per the docs:
CURLOPT_RETURNTRANSFER
-TRUE
to return the transfer as a string of the return value ofcurl_exec()
instead of outputting it out directly.
Have you tried?
curl_setopt($ch, CURLOPT_VERBOSE, 0);
This worked for me!
after php 5.1 curl
will display always result you can view in documentation. for avoid it simply use
echo "< span style='display:none'>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 12);
$result = curl_exec($ch);
curl_close ($ch);
echo"< /span>";
精彩评论