php 实现简易 RSS 阅读器

阅读更多
                $type = 'qq';
		$ch = curl_init();
		
		//网易新闻头条
		//curl_setopt($ch,CURLOPT_URL,"http://news.163.com/special/00011K6L/rss_newstop.xml");
		//网易国内新闻
		//curl_setopt($ch,CURLOPT_URL,"http://news.163.com/special/00011K6L/rss_gn.xml");
		//网易国际新闻
		//curl_setopt($ch,CURLOPT_URL,"http://news.163.com/special/00011K6L/rss_gj.xml");

		
		//sina新闻要闻
		//curl_setopt($ch,CURLOPT_URL,"http://rss.sina.com.cn/news/marquee/ddt.xml");
		//sina国内要闻
		//curl_setopt($ch,CURLOPT_URL,"http://rss.sina.com.cn/news/china/focus15.xml");
		//sina国际要闻
		//curl_setopt($ch,CURLOPT_URL,"http://rss.sina.com.cn/news/world/focus15.xml");
		
		//腾讯国内要闻
		curl_setopt($ch,CURLOPT_URL,"http://news.qq.com/newsgn/rss_newsgn.xml");
		//腾讯国际要闻
		//curl_setopt($ch,CURLOPT_URL,"http://news.qq.com/newsgj/rss_newswj.xml");
		
		curl_setopt($ch,CURLOPT_HEADER,0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
		$sContent = curl_exec($ch);
		curl_close($ch);

		if($type='sina'){
			//去除CDATA标识
			$sContent = str_replace('','',$sContent);
		}
		$rss_arr = xmlToArray($sContent);
		$tems = $rss_arr['rss']['channel']['item'];
		foreach ($tems as $value) {
			$date_time = strtotime($value['pubDate']);
			echo 'pubDate='.date('Y-m-d H:i:s',$date_time);
			echo '
'; echo 'title='.$value['title'].''; echo '
'; echo 'link='.$value['link']; echo '
'; if($type='163'){ //去除冗余信息 $desc = $value['description']; $desc = explode('......',$desc); echo 'description='.$desc[0].'......'; }else{ echo 'description='.$value['description']; } echo '
'; }

 
php 实现简易 RSS 阅读器_第1张图片
 http://huangqiqing123.iteye.com/blog/1882047

 

  • php 实现简易 RSS 阅读器_第2张图片
  • 大小: 55.2 KB
  • 查看图片附件

你可能感兴趣的:(rss,php)