专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »PHP教程 » php函数:php中几个文件读取函数的贴心功能 »正文

php函数:php中几个文件读取函数的贴心功能

来源: 发布时间:星期一, 2009年1月12日 浏览:48次 评论:0
  1、用file_get_contents或者fopen、file、readfile等读取url时候会创建个名为$http_response_header变量来保存http响应报头使用fopen等打开数据流信息可以用stream_get_meta_data来获取

  2、php5中新增参数context使这些更加灵活通过它我们可以定制http请求甚至post数据

  举例代码1:

<?php
$html = file_get_contents('http://www.example.com/');
pr_r($http_response_header);
 
// or
$fp = fopen('http://www.example.com/', 'r');
pr_r(stream_get_meta_data($fp));
fclose($fp);
?>
举例代码2:

<?php
$data = .gif' /> ('foo' => 'bar');
$data = http_build_query($data);
 
$opts = .gif' /> (
  'http' => .gif' /> (
    'method' => 'POST',
    'header'=> "Content-type: application/x-www-form-urlencodedrn" .
            "Content-Length: " . strlen($data) . "rn",
    'content' => $data
  ),
);
 
$context = stream_context_create($opts);
$html = file_get_contents('http://www.example.com', false, $context);
 
echo $html;
?>


0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: