[PHP]使用file_get_content

来源:互联网 发布:js比较字符串 编辑:程序博客网 时间:2024/05/29 18:41

file_get_contents( path , include_path , context , start , max_length)

参数 描述 path 必需。规定要读取的文件。 include_path 可选。如果也想在 include_path 中搜寻文件的话,可以将该参数设为 “1”。 context 可选。规定文件句柄的环境。 context 是一套可以修改流的行为的选项。若使用 null,则忽略。 start 可选。规定在文件中开始读取的位置。该参数是 PHP 5.1 新加的。 max_length 可选。规定读取的字节数。该参数是 PHP 5.1 新加的。
<?php$hdrs = array(  'http' =>array(      'header' =>            "Accept: application/json\r\n" .           "Accept-Encoding: gzip, deflate\r\n" .           "Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3\r\n" .           "Connection: keep-alive\r\n" .           "Cookie: mzys_is_frist_access=1; PHPSESSID=4kacoqfe4ae33km3h0l2imjfd6\r\n" .           "Host: http://1212.ip138.com/ic.asp\r\n" .           "Referer: http://1212.ip138.com/ic.asp\r\n" .           "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0\r\n" .           "X-Requested-With: XMLHttpRequest",           'timeout'=>2        ),    'content' => http_build_query($post, '', '&'),);$context = stream_context_create($hdrs);//方式1echo file_get_contents('http://1212.ip138.com/ic.asp', 0, $context);print_r($http_response_header); // 显示返回的头信息  //方式2// $fp = fopen("http://1212.ip138.com/ic.asp", 'r', false, $context);// fpassthru($fp);// fclose($fp);

失败重试

$cnt=0;while($cnt < 3 && ($str=@file_get_contents('http...'))===FALSE) $cnt++;

原文

阅读全文
0 0