使用php获取网页内容

方法有很多

1。使用xmlhttp对象,类似于asp中的ActiveXObject对象,其实xmlhttp无非就是get和put的操作,在php里面

get的,直接用file_get_contents/fopen/readfile这些函数就是了

put的,自己写fsockopen发送也行,用NET_Curl也行

(直接用系统函数要简单,通用,耗费资源少)

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

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值