• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

[原创]替找房方便 ,将sohu焦点的 rss 改成全文的

php 搞代码 4年前 (2022-01-23) 28次浏览 已收录 0个评论

[原创]为找房方便 ,将sohu焦点的 rss 改成全文的.
房价貌似快要涨了,俺最近天天加班,俺媳妇来负责找房源,可她那狗屎公司无法上网,只好用ipad 加载rss 离线看,结果狗屎sohu焦点的rss 非全文rss ,为了老婆找房方便,写了点代码,用于生成全文的rss. 希望借此机会,尝试一下代码改善生活的感觉. 不废话吧,直接贴代码了.

PHP code

<!---ecms -ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpheader("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 = '<?xml version="1.0" encoding="GBK"?><?xml-stylesheet type="text/xsl" href="/common/xml/xsl/rss.xsl" media="all"?><?xml-stylesheet type="text/css" href="/common/xml/css/rss.css" media="all"?><title></title><link>http://sz.focus.cn/newscenter/xwsy.htmlhttp://images.house.focus.cn/img/newhouselogo.gif<title>热点新闻-搜狐焦点网深圳站</title><link>http://sz.focus.cn/newscenter/xwsy.htmlCopyright 2012, sohu.com Inc., all rights reservedzh-cnMon, 02 Jul 2012 21:44:21 +0800Mon, 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]+)<div>/iU" , $urlContent , $matchArr);    $item->description = $matchArr[1];    return $item;}/** * @param $itemObjArr * @return string */function makeRssItemSt<i style="color:transparent">本#文来源gaodai$ma#com搞$$代**码网$</i><button>搞代gaodaima码</button>ring( $itemObjArr ){   $result = "";   foreach( $itemObjArr as $itemObj  ):       $result .= "";           $result .= "<title>title ]]></title>";           $result .= "<link>$itemObj->link";           $result .= "description ]]>";           $result .= "mu_rain";           $result .= "$itemObj->pubDate";       $result .= "";   endforeach;    return  $result;}// ------------------------------------/** * regulary show the string or object or json. * 规格化显示 * * @param  $str    对象的实例 * @package        P * @subpackage    String * @category    Putils * @author        mu_rain *  @return mixed */// ------------------------------------function pr($array,$title = 'DEBUG',$type = 'array' , $width = '')    {    $title .= date("Y-m-d H:i:s");    $widthStr = "";    if( $width) $widthStr = "width:$width"."px";    echo "<fieldset><legend style="color: #069;margin:3px;$widthStr">$title</legend>";    echo "<div style='font-size:14px;color:#069;border:1px solid #F0FAF9;font-size:9pt;background:#F0FAF9;padding:5px'>";    print("<pre class="prettyprint linenums">");    if($type == 'json') {        $array = json_decode($array);    }    print_r($array);    print("

“); echo “

“; echo “

“;}// ————————————/** * * get the urlContent use curl * @package KDG * @subpackage common * @category mu_rain * @author 徐兴 */// ————————————function fileGetContent($url){ $ch = curl_init(); $timeout = 30; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $contents = trim(curl_exec($ch)); curl_close($ch); return $contents;}


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:[原创]替找房方便 ,将sohu焦点的 rss 改成全文的
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址