php CURL中这个参数如何理解?

我想问下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; 
  }  
  ?>
阅读 2.5k
1 个回答

CURLOPT_HEADERFUNCTION A callback accepting two parameters. The first is the cURL resource, the second is a string with the header data to be written. The header data must be written by this callback. Return the number of bytes written.
http://cn2.php.net/manual/en/...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题