时间:2021-07-01 10:21:17 帮助过:10人阅读
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="">
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];