Windows10系统下载,Win10激活,Win10教程

PHP文件读取函数的便捷功能

http://www.zftb.cn  发布时间:2015-03-05 17:05 来源:未知 浏览:加载中
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'); 
print_r($http_response_header);  
// or 
$fp = fopen('http://www.example.com', 'r'); 
print_r(stream_get_meta_data($fp)); 
fclose($fp); 
?>


示例代码2:
<?php 
$data = array ('foo' => 'bar'); 
$data = http_build_query($data); 
$opts = array ( 
    'http' => array ( 
        'method' => 'POST', 
        'header'=> "Content-type: application/x-www-form-urlencoded\\r\\n" . 
                   "Content-Length: " . strlen($data) . "\\r\\n", 
        'content' => $data 
    ), 
); 
$context = stream_context_create($opts); 
$html = file_get_contents('http://www.example.com', false, $context); 
echo $html; 
?>

如果你有好的win10资讯或者win10教程,以及win10相关的问题想要获得win10系统下载的关注与报道。
欢迎加入发送邮件到657025171#qq.com(#替换为@)。期待你的好消息!