[原创]为找房方便 ,将sohu焦点的 rss 改成全文的.
<br> <?php <br /> header("Content-type: text/html; charset=utf-8");<br> ini_set("max_excution_time" ,3600);<br> $url = "http://sz.focus.cn/common/xml/rss/news/hot.php";<br> <br> $newItemArr = parseItems( $url );<br> $xmlItemContent = makeRssItemString( $newItemArr ); //重新生成item 内容,将下载内容替换descript.<br> <br> //rss xml 的头尾字符串<br> $xmlPre = '<br> <?xml version="1.0" encoding="GBK"?><br> <?xml-stylesheet type="text/xsl" href="/common/xml/xsl/rss.xsl" media="all"?><br> <?xml-stylesheet type="text/css" href="/common/xml/css/rss.css" media="all"?><br> <br> <rss></rss> xmlns:focus="http://house.focus.cn"<br> xmlns:F="http://house.focus.cn"<br> docType="rss"<br> F:docType="rss"<br> ><br> <channel></channel> pageIndex=""<br> pageSize="20"<br> recordCount=""<br> F:pageIndex=""<br> F:pageSize="20"<br> F:recordCount=""><br> <image><br> <title></title> <br> <link>http://sz.focus.cn/newscenter/xwsy.html<br> <url>http://images.house.focus.cn/img/newhouselogo.gif</url><br> </image><br> <title>热点新闻-搜狐焦点网深圳站</title><br> <link>http://sz.focus.cn/newscenter/xwsy.html<br> <description></description><br> <copyright>Copyright 2012, sohu.com Inc., all rights reserved</copyright><br> <language>zh-cn</language><br> <lastbuilddate>Mon, 02 Jul 2012 21:44:21 +0800</lastbuilddate><br> <pubdate>Mon, 02 Jul 2012 21:44:21 +0800</pubdate><br> <category>地产综合</category><br> <ttl>30</ttl>';<br> $xmlAppend = '';<br> <br> <br> $xmlOutput = $xmlPre . $xmlItemContent . $xmlAppend ;<br> echo $xmlOutput;<br> <br> <br> /**<br> * @param $url<br> * @return array itemObj<br> */<br> function parseItems( $url )<br> {<br> $xmlObj = simplexml_load_file( $url );<br> $items = $xmlObj -> channel -> item;<br> <br> $resultArr = array();<br> <br> foreach( $items as $item ):<br> $resultArr []= makeRssItemObj( $item );<br> endforeach;<br> <br> return $resultArr;<br> }<br> <br> <br> <br> /**<br> * @param $item<br> * @return itemObj<br> */<br> function makeRssItemObj( $item )<br> {<br> // $item->link = "demo.html";<br> $urlContent = fileGetContent( $item->link ); //如果不支持curl 就用file_get_content 或者socket 连接来实现.<br> <br> $urlContent = @iconv("gb2312","utf-8",$urlContent);<br> <br> // $content = iconv("gb2312" , "utf-8" , $content);<br> preg_match("/id=\"newscontent\">([\d\D]+)<div>/iU" , $urlContent , $matchArr);<br> <br> $item->description = $matchArr[1]; <div class="clear"> </div> </div>