我想问下CURLOPT_HEADERFUNCTION和CURLOPT_WRITEFUNCTION参数如何理解?我不知道怎么使用,php手册上说的很模糊不懂。
这是github上找到的一个例子,但是使用的时候并没有给$string传值啊,这个值是从何而来?
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.php.net/');
// Set callback function for headers
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');
// Set callback function for body
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body');
curl_exec($ch);
if ($error = curl_error($ch)) {
echo "Error: $error<br />\n";
}
function read_header($ch, $string) {
$length = strlen($string);
echo "Header1: $string<br />\n";
return $length;
}
function read_body($ch, $string) {
$length = strlen($string);
echo "Received $length bytes<br />\n";
return $length;
}
?>