首页 »PHP教程 » php函数:php中几个文件读取函数的贴心功能 »正文
php函数:php中几个文件读取函数的贴心功能
来源: 发布时间:星期一, 2009年1月12日 浏览:48次 评论:0
1、用file_get_contents或者fopen、file、readfile等 ![](/icons/58108hanshu.gif) 读取url ![](/icons/58108de.gif) 时候 ![](/icons/58108dou.gif) 会创建 ![](/icons/58108yi.gif) 个名为$http_response_header ![](/icons/58108de.gif) 变量来保存http响应 ![](/icons/58108de.gif) 报头 ![](/icons/58108dou.gif) 使用fopen等 ![](/icons/58108hanshu.gif) 打开 ![](/icons/58108de.gif) 数据流信息可以用stream_get_meta_data来获取 ![](/icons/58108dou2.gif) 2、php5中新增 ![](/icons/58108de.gif) 参数context使这些 ![](/icons/58108hanshu.gif) 更加灵活 ![](/icons/58108dou.gif) 通过它我们可以定制http请求 ![](/icons/58108dou.gif) 甚至post数据 ![](/icons/58108dou2.gif) 举例代码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; ?>
相关文章
读者评论
发表评论
|
|