首頁 >php教程 >php手册 >新闻捕捉器php

新闻捕捉器php

WBOY
WBOY原創
2016-06-13 10:23:59896瀏覽


// PHP Headlines Grabber by Neil Moomey, www.neilmoomey.com.
// You are free to use this code as you wish.
// Make sure you get permission from any web sites you grab headlines from.
// You may want to write the headlines to a file on your server to speed things up.

// Grab source code from a file or web site
if(!($myFile=fopen("http://www.lndaily.com.cn/web/yw3.htm","r")))
{
echo "The news interface is down for maintenance.";
exit;
}
while(!feof($myFile))
{
// Read each line and add to $myLine
$myLine.=fgets($myFile,255);
}
fclose($myFile);
// Extract everything between start and end. You need to include these lines
//in the headlines or pick some unique substring in the html to mark the start
//and end of the news.
$start="


$start_position=strpos($myLine, $start);
$end_position=strpos($myLine, $end)+strlen($end);

$length=$end_position-$start_position;
$myLine=substr($myLine, $start_position, $length);
// Display HTML
echo $myLine;
?>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn