Don't Echo Out cURL

PhpCurl

Php Problem Overview


When I use this code:

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

I am returned what I want, but if I just use that - $statuses is echoed out onto the page.

How can I stop this?

Php Solutions


Solution 1 - Php

Put this on line 2:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

Solution 2 - Php

Include this option before curl_exec()

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

Solution 3 - Php

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontarnfeldView Question on Stackoverflow
Solution 1 - PhpMatt McCormickView Answer on Stackoverflow
Solution 2 - PhpDominic BarnesView Answer on Stackoverflow
Solution 3 - PhppatrickView Answer on Stackoverflow