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('<![CDATA[','',$sContent);
			$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 '<br>';
			echo 'title=<a href="'.$value['link'].'" target="_blank">'.$value['title'].'</a>';
			echo '<br>';
			echo 'link='.$value['link'];
			echo '<br>';
			
			if($type='163'){
				//去除冗余信息
				$desc = $value['description'];
				$desc = explode('......',$desc);
				echo 'description='.$desc[0].'......';
			}else{
				echo 'description='.$value['description'];
			}
			echo '<hr>';
		}

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

 

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