求教:怎样取http页面内容?

edlongren 2003-07-19 03:08:51
File:
<?
$filename="http://www.csdn.net/";
$fp=@fopen($filename,"r");
echo $fp."<br>\n";
$body=@fread($fp,filesize($filename));
if ($body==""){
echo "no math!";
}else{
$body2=nl2br("$body");
echo $body2;
}
@fclose();
?>

我想取得任一网页中的内容,然后显示出来,
应该如何编写?
(我写的只能取出文件中的内容)
...全文
39 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
vitalgg 2003-07-19
  • 打赏
  • 举报
回复
<?php
$theaddr = "www.csdn.net";
error_reporting (E_ALL);
$service_port = getservbyname('www', 'tcp');
$address = gethostbyname ($theaddr);
$socket = socket_create(AF_INET, SOCK_STREAM, 0);

$result = socket_connect($socket, $address, $service_port);
if ($result < 0) {
$the_info = "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
} else {
$the_info = "OK.\n";
}
if (isset($_GET['info'])) {
echo $the_info."<br>";
}
$in = "GET / HTTP/1.0\r\nHost: $theaddr\r\n\r\n";
$out = '';
$the_contect = '';
socket_write ($socket, $in, strlen ($in));

for ($i = 0; $i < 100; $i++) {
$out = socket_read($socket,2048);
$the_contect .= $out;
}

echo "<textarea name=me rows=40 cols=120>$the_contect</textarea>";

socket_close ($socket);
?>
feel8 2003-07-19
  • 打赏
  • 举报
回复
用 file 函数?
bonniewater 2003-07-19
  • 打赏
  • 举报
回复
具体点吧
vitalgg 2003-07-19
  • 打赏
  • 举报
回复
用socket 80口读取.
bonniewater 2003-07-19
  • 打赏
  • 举报
回复
不对呀,你的代码有问题
$body=@fread($fp,$);
if (strlen($body)<0){
这两句都不对,而且echo $body; 什么也没有!
bonniewater 2003-07-19
  • 打赏
  • 举报
回复
学习了一个
edlongren 2003-07-19
  • 打赏
  • 举报
回复
问题已经解决~:)
贴出来大家参考~!!
<?
$filename="http://www.csdn.net/";
$fp=@fopen($filename,"r");
$body=@fread($fp,$);
if (strlen($body)<0){
echo "no math!";
}else{
echo $body;
}
@fclose();
?>
edlongren 2003-07-19
  • 打赏
  • 举报
回复
问题已经解决~:)

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧