海上月明

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

使用php获取网页内容

Posted on 2007-02-10 23:09 pts 阅读(3420) 评论(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页面的编码不一样当然乱码.

博问 - 解决您的IT难题
博客园  博问  IT新闻  Java程序员招聘
标题  
姓名  
主页
验证码 *  
内容(请不要发表任何与政治相关的内容)  
  登录      


网站导航: