|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
截取yahoo.com.cn新闻[仅供实验] 有很多截取首页新闻的程序,但是并不能成功。 他们的工作原理无非两种,一种是采用某些网站称之为backend的后端数据库接口,另一种则是硬声声的根据html代码截取。本程序采用的是后者。应该说,容错性能比较好。 <? $open = fopen("http://www.yahoo.com.cn/index.html", "r");//网页地址 $read = fread($open, 15000); fclose($open); $search = eregi("<!-- Start in the news -->(.*)<!-- End in the news -->", $read, $printing);//截取一段源代码,最好先分析一下源代码 //以下开始取出容余源代码 $printing[1] = str_replace("href="/homer/?", "href="", $printing[1]); $printing[1] = str_replace("href="/headlines/fullcoverage/", "href="http://www.yahoo.com.cn/headlines/fullcoverage/", $printing[1]); $printing[1] = str_replace("</td></tr><tr><td valign=top align=right>", "", $printing[1]); $printing[1] = str_replace("</td><td>", "", $printing[1]); $printing[1] = str_replace(" class=sbody", "", $printing[1]); $printing[1] = str_replace("</small>", "", $printing[1]); $content = $printing[1]; $content = explode("-", $content); $headlines = sizeof($content); for ($i = 0; $i < $headlines; $i++) { print "新闻".($i+1).") : $content[$i]<BR>";//激动人心的时刻到了!显示出来了! } ?> 在php3/php4 apache下调试通过。 返回类别: 教程 上一教程: PHP编程:探索字串的奥秘 下一教程: PHP个人网站架设连环讲(三) 您可以阅读与"也谈截取首页新闻 - 范例"相关的教程: · 用文本文件实现的动态实时发布新闻的程序 · 在 php 中使用 sockets:从新闻组中获取文章 · 也谈 PHP 和 MYSQL · 在php中使用sockets:从新闻组中获取文章 · 是一个设计将LinuxFreak.org新闻标题放置到你的网站的PHP脚本程序。 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |