Use*_*407 9

我知道这是一个老问题,但也许我的回答对你或其他人有所帮助.WRITEFUNCTION用于处理文本,因为它在流入或基于某些条件中止下载.这是一个简单地将所有文本放入大写字母的示例:

function get_html($url){
    $ch = curl_init();
    $obj = $this;//create an object variable to access class functions and variables
    $this->result = '';
    $callback = function ($ch, $str) use ($obj) {
        $obj->result .= strtoupper($str);
        return strlen($str);//return the exact length
    };
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_WRITEFUNCTION, $callback);
    curl_exec($ch);
    curl_close($ch);
    return $this->result;
}
Run Code Online (Sandbox Code Playgroud)

要查看我如何使用它,请查看此链接:并行cURL请求与WRITEFUNCTION回调.


Sar*_*raz 1

它与curl_setopt功能一起使用。

CURLOPT_WRITEFUNCTION是回调函数的名称,其中回调函数有两个参数。第一个是 cURL 资源,第二个是包含要写入的数据的字符串。必须使用此回调函数写入数据。必须返回写入的确切字节数,否则将会失败。