///////////////////////////////  体育新闻////////////////////////////
echo "start.....";
$dir="D:/web/news_from_sina/";
$t1=time();
$name=date("n.d").".shtml";
$fp=fopen("http://sports.sina.com.cn/date_2003/".$name,"r");
$str="";
while($d=@fgets($fp,1000))
{ $str.=$d;}
$fp2=@fopen($dir."sports.html","w+");
@fputs($fp2,$str);
@fclose($fp2);
@fclose($fp);
$date1=date("Y-n-d");
///////////////////////////////  国内新闻////////////////////////////$fp=@fopen("http://news.sina.com.cn/china/".$date1."/","r");
$str="";
while($d=@fgets($fp,1000))
{ $str.=$d;}
$fp2=@fopen($dir."china.html","w+");
@fputs($fp2,$str);
@fclose($fp2);
@fclose($fp);///////////////////////////////  国际新闻////////////////////////////$fp=@fopen("http://news.sina.com.cn/world/".$date1."/","r");
$str="";
while($d=@fgets($fp,1000))
{ $str.=$d;}
$fp2=@fopen($dir."world.html","w+");
@fputs($fp2,$str);
@fclose($fp2);
@fclose($fp);///////////////////////////////  社会新闻////////////////////////////$fp=@fopen("http://news.sina.com.cn/society/".$date1."/","r");
$str="";
while($d=@fgets($fp,1000))
{ $str.=$d;}
$fp2=@fopen($dir."society.html","w+");
@fputs($fp2,$str);
@fclose($fp2);
@fclose($fp);///////////////////////////////  科技新闻////////////////////////////$fp=@fopen("http://tech.sina.com.cn/roll.shtml","r");
$str="";
while($d=@fgets($fp,1000))
{ $str.=$d;}
$fp2=@fopen($dir."tech.html","w+");
@fputs($fp2,$str);
@fclose($fp2);
@fclose($fp);///////////////////////////////  文教新闻////////////////////////////$fp=@fopen("http://edu.sina.com.cn/i/index.shtml","r");
$str="";
while($d=@fgets($fp,1000))
{ $str.=$d;}
$fp2=@fopen($dir."study.html","w+");
@fputs($fp2,$str);
@fclose($fp2);
@fclose($fp);///////////////////////////////  军事新闻////////////////////////////$fp=@fopen("http://jczs.sina.com.cn/junshi/index.shtml","r"); //国内军事
$str="";
while($d=@fgets($fp,1000))
{ $str.=$d;}
$fp2=@fopen($dir."jushi1.html","w+");
@fputs($fp2,$str);
@fclose($fp2);
@fclose($fp);$fp=@fopen("http://jczs.sina.com.cn/junqing/index.shtml","r");//周边局势
$str="";
while($d=@fgets($fp,1000))
{ $str.=$d;}
$fp2=@fopen($dir."jushi2.html","w+");
@fputs($fp2,$str);
@fclose($fp2);
@fclose($fp);$fp=@fopen("http://jczs.sina.com.cn/junli/index.shtml","r");//世界军事
$str="";
while($d=@fgets($fp,1000))
{ $str.=$d;}
$fp2=@fopen($dir."jushi3.html","w+");
@fputs($fp2,$str);
@fclose($fp2);
@fclose($fp);
//////////////////////////////////图片新闻///////////////////
/*$fp=@fopen("http://news.china.com/zh_cn/photonews/inner/","r");//周边局势
$str="";
while($d=@fgets($fp,1000))
{ $str.=$d;}
$fp2=@fopen($dir."photo.html","w+");
@fputs($fp2,$str);
@fclose($fp2);
@fclose($fp);*/
/////////////////////////////////完毕////////////////////////////
$t2=time();
$t=$t2-$t1;
$t="耗时 ".$t." 秒";
echo $t;

解决方案 »

  1.   

    /*
    国内新闻  1  国际新闻 2  社会新闻 3  文化教育新闻 4 体育新闻 5 科技新闻 6 军事新闻 7
    */
    //////////////////////////////////////////////////////////////////////////
    //////////////////////////////////  国内新闻部分 ////////////////////////
    /////////////////////////////////////////////////////////////////////////
    $dir="D:/web/news_from_sina/";
    $fp=@fopen($dir."china.html","r");
    //$str=file($dir."china.html");
    $contents = fread($fp, filesize($dir."china.html"));
    $str=$contents;
    ////////////////////////////// 处理列表///////////////////////////////////////
    $str_ary = explode("<!--开始新闻列表-->",$str);
    $str_ary2 = explode("<!--结束新闻列表-->",$str_ary[1]);
    $str=substr($str_ary[1],0,strlen($str_ary[1])-strlen($str_ary2[1])-28);

    ////////////////////////////////////   处理标题///////////////////////////
    echo "<font color=red>国内新闻</font><br>";
    $i=1;
    $str_ary = explode("\n",$str);
    $title=$str_ary;
    $scorce="新浪网";
    $t=$str_ary;
    $pic=$str_ary;
    $url=$str_ary;
    for($j=1;$j<count($title);$j++)
    {
    //////////////////////  处理连接//////////////////////
     $url1=explode("href=",$url[$j]);
     $url2= explode("html",$url1[1]);
     $url[$j]=substr($url1[1],0,strlen($url1[1])-strlen($url2[1]));
     if(substr($url[$j],0,7)!="http://")
     $url[$j]="http://news.sina.com.cn".$ttt.$url[$j];
    //////////////////////////////  处理时间//////////////////////  
    $title[$j]=strip_tags(str_replace("★","",$title[$j]));
    $t[$j]=substr($title[$j],strlen($title[$j])-16,15);
    $t[$j]=substr($t[$j],0,4)."-".substr($t[$j],4,2)."-".substr($t[$j],6,2).substr($t[$j],9,15-8);
    if(substr($t[$j],0,2)!="20")
    $t[$j]=date("Y-m-d H:i");
    ///////////////////////////处理标题/////////////////////////
        $title[$j]=ltrim(trim(substr($title[$j],0,strlen($title[$j])-18)));
    $ck=substr($title[$j],strlen($title[$j])-6,4);
    if($ck=="(图)") $pic[$j]=1; else $pic[$j]=0;
    /////////////////////////////////  写进数据库/////////////////////
    $sql="SELECT `title` from `news` where `title`='$title[$j]' AND `t`='$t[$j]'";
    $rs=@mysql_query($sql);
    $num=@mysql_num_rows($rs);
    if($num==0)
    {
    $sql="INSERT INTO `news` (`id`,`title`,`url`,`t`,`scorce`,`hits`,`typeid`) values('','$title[$j]','$url[$j]','$t[$j]','$scorce',1,'1')";
    @mysql_query($sql);
    }
    }

      

  2.   

    /date_2003/把后面的2003也变换成
    date("Y")
    那就更灵活了