海上月明

editer by sun
posts - 162, comments - 51, trackbacks - 0, articles - 8
   :: 首页 :: 新随笔 ::  :: 聚合  :: 管理

使用php获取网页内容

Posted on 2007-02-10 23:09 pts 阅读(5263) 评论(1)  编辑  收藏
简单的做法:
<?php
$url="http://www.blogjava.net/pts";
echo file_get_contents( $url );
?>
或者:
<?
if ($stream = fopen('http://www.sohu.com', 'r')) {
    // print all the page starting at the offset 10
    echo stream_get_contents($stream, -1, 10);
    fclose($stream);
}

if ($stream = fopen('http://www.sohu.net', 'r')) {
    // print the first 5 bytes
    echo stream_get_contents($stream, 5);
    fclose($stream);
}
?>

但是如果将url换成自己的bolg时,返回的中文显示为乱码?


powered by performancing firefox


评论

# re: 使用php获取网页内容  回复  更多评论   

2007-08-26 09:05 by 愚昧
你获取的文件编码和你的PHP页面的编码不一样当然乱码.

只有注册用户登录后才能发表评论。


网站导航: