curl_exec printing results when I don't want to

前端 未结 3 647
广开言路
广开言路 2020-12-04 23:18

I am using the following code:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_TIMEOUT, 12); 

$result = curl_exec($ch);

         


        
3条回答
  •  一整个雨季
    2020-12-04 23:48

    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 of curl_exec() instead of outputting it out directly.

提交回复
热议问题