[原創]為找房方便 ,將sohu焦點的 rss 改成全文的.解決方案

來源:互聯網
上載者:User
[原創]為找房方便 ,將sohu焦點的 rss 改成全文的.
本帖最後由 PhpNewnew 於 2012-07-03 07:50:15 編輯

樓價貌似快要漲了,俺最近天天加班,俺媳婦來負責找房源,可她那狗屎公司無法上網,只好用ipad 載入rss 離線看,結果狗屎sohu焦點的rss 非全文rss ,為了老婆找房方便,寫了點代碼,用於產生全文的rss. 希望藉此機會,嘗試一下代碼改善生活的感覺. 不廢話吧,直接貼代碼了.

header("Content-type: text/html; charset=utf-8");
ini_set("max_excution_time" ,3600);
$url = "http://sz.focus.cn/common/xml/rss/news/hot.php";

$newItemArr = parseItems( $url );
$xmlItemContent = makeRssItemString( $newItemArr ); //重建item 內容,將下載內容替換descript.

//rss xml 的頭尾字串
$xmlPre = '




xmlns:focus="http://house.focus.cn"
xmlns:F="http://house.focus.cn"
docType="rss"
F:docType="rss"
>
pageIndex=""
pageSize="20"
recordCount=""
F:pageIndex=""
F:pageSize="20"
F:recordCount="">

<![CDATA[熱點新聞-搜狐焦點網深圳站 ]]>
http://sz.focus.cn/newscenter/xwsy.html
http://images.house.focus.cn/img/newhouselogo.gif

熱點新聞-搜狐焦點網深圳站
http://sz.focus.cn/newscenter/xwsy.html
提供最全面最及時的中國房地產新聞資訊
Copyright 2012, sohu.com Inc., all rights reserved
zh-cn
Mon, 02 Jul 2012 21:44:21 +0800
Mon, 02 Jul 2012 21:44:21 +0800
地產綜合
30';
$xmlAppend = '';


$xmlOutput = $xmlPre . $xmlItemContent . $xmlAppend ;
echo $xmlOutput;


/**
* @param $url
* @return array itemObj
*/
function parseItems( $url )
{
$xmlObj = simplexml_load_file( $url );
$items = $xmlObj -> channel -> item;

$resultArr = array();

foreach( $items as $item ):
$resultArr []= makeRssItemObj( $item );
endforeach;

return $resultArr;
}



/**
* @param $item
* @return itemObj
*/
function makeRssItemObj( $item )
{
// $item->link = "demo.html";
$urlContent = fileGetContent( $item->link ); //如果不支援curl 就用file_get_content 或者socket 串連來實現.

$urlContent = @iconv("gb2312","utf-8",$urlContent);

// $content = iconv("gb2312" , "utf-8" , $content);
preg_match("/id=\"newscontent\">([\d\D]+)/iU" , $urlContent , $matchArr);

$item->description = $matchArr[1];
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.