使用php获取网页内容
2007-10-11 18:26
661 查看
方法有很多
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);
}
?>
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);
}
?>
相关文章推荐
- PHP 使用 stream_get_meta_date ,stream_get_contents 获取网页内容
- 使用php获取网页内容
- PHP中使用curl库获取网页内容如何P…
- php使用fsockopen函数发送post,get请求获取网页内容的方法
- php使用fsockopen函数发送post,get请求获取网页内容的方法
- 使用php获取网页内容
- HtmlParser应用,使用Filter从爬取到的网页中获取需要的内容
- 【php】获取网页内容
- 使用PHP简单网页抓取和内容分析
- 使用SOCKET获取网页的内容
- VB使用xmlhttp获取远程网页内容
- 使用CInternetSession 获取网页内容。。。解决了ReadString时的乱码
- Python获取网页内容、使用BeautifulSoup库分析html
- HtmlParser应用,使用Filter从爬取到的网页中获取需要的内容
- PHP远程获取网页内容
- 使用HtmlUnit模拟浏览器执行JS来获取网页内容
- 使用phpQuery轻松采集网页内容
- PHP抓取网页内容,获取链接绝对路径和图片绝对路径
- 使用XPath解析HTML获取网页内容