不要回声

当我使用这个代码时:

$ch = curl_init($url);
$statuses = curl_exec($ch);
curl_close($ch);

我得到了我想要的返回值,但是如果我只使用这个返回值-$statuses就会回显到页面上。

我怎么才能阻止这一切?

71613 次浏览

Put this on line 2:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

Include this option before curl_exec()

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

In addition to the accepted answer, make sure you didn't set CURLOPT_VERBOSE to true, if you add this

curl_setopt($ch, CURLOPT_VERBOSE, true );

there will be output from cUrl, even with CURL_RETURNTRANSFER set to true