查看文章
 
使用php获取网页内容
2008-01-13 15:11

我的  手工艺小站

 

header("Content-type: text/html; charset=utf-8");

1

$xhr = new COM("MSXML2.XMLHTTP");
$xhr->open("GET","http://localhost/xxx.php?id=2",false);
$xhr->send();
echo $xhr->responseText

2。file_get_contents实现

<?php
$url="http://www.blogjava.net/pts";
echo file_get_contents( $url );
?>

3。fopen()实现

<?
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);
}
?>

类别:默认分类||添加到搜藏 |分享到i贴吧|浏览(3466)|评论 (0)
 
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
     

   
帮助中心 | 空间客服 | 投诉中心 | 空间协议
©2012 Baidu