您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP读取网页文件内容的实现代码(fopen,curl等)

2024/3/15 9:13:35发布28次查看
php小偷程序中经常需要获取远程网页的内容,下面是一些实现代码,需要的朋友可以惨况下。
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);
?>
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product