1.fopen实现代码:
复制代码 代码如下:
复制代码 代码如下:
2.curl实现代码:
复制代码 代码如下:
编码转换函数
复制代码 代码如下:
$html = file_get_contents(http://s.jb51.net);
$html = iconv( big5, utf-8//ignore , $html); //转化编码方式为utf8
print $html;
$htm = file(http://s.jb51.net);
$h = ;
foreach($htm as $value)
{
$h.= iconv( gb2312, utf-8//ignore , $value);
}
print_r($h);
另一种打开网页的方法
复制代码 代码如下:
array(
'method'=>get,
'header'=>accept-language: en\r\n .
cookie: foo=bar\r\n
)
);
$context = stream_context_create($opts);
/* sends an http request to www.example.com
with additional headers shown above */
$fp = fopen('http://www.baidu.com', 'r', false, $context);
fpassthru($fp);
fclose($fp);
?>
以上就介绍了fop php读取网页文件内容的实现代码fopen,curl等,包括了fop方面的内容,希望对php教程有兴趣的朋友有所帮助。