我知道这是一个老问题,但也许我的回答会对您或其他人有所帮助。 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;
}
要了解我如何使用它,请查看此链接:带有 WRITEFUNCTION 回调的并行 cURL 请求 https://stackoverflow.com/questions/15906261/parallel-curl-request-with-writefunction-callback/15958698#15958698.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)