[原创]替找房方便,将sohu焦点的rss改成全文的
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了[原创]替找房方便,将sohu焦点的rss改成全文的,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2969字,纯文字阅读大概需要5分钟。
内容图文
![[原创]替找房方便,将sohu焦点的rss改成全文的](/upload/InfoBanner/zyjiaocheng/216/58b6c160c7d9436880255e28ae8d964e.jpg)
房价貌似快要涨了,俺最近天天加班,俺媳妇来负责找房源,可她那狗屎公司无法上网,只好用ipad 加载rss 离线看,结果狗屎sohu焦点的rss 非全文rss ,为了老婆找房方便,写了点代码,用于生成全文的rss. 希望借此机会,尝试一下代码改善生活的感觉. 不废话吧,直接贴代码了.
- PHP code
- ";
$result .= "
title ]]> "; $result .= "$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 style=\"-moz-border-radius:5px 5px 5px 5px; -moz-box-shadow:0px 0px 10px rgba(00,00,00,0.45); border: 3px solid transparent; padding:3px; margin-top:20px; \"><legend style=\"color: #069; margin:3px; $widthStr \">$title"; echo ""; print("
"); 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; } - "; 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 style=\"-moz-border-radius:5px 5px 5px 5px; -moz-box-shadow:0px 0px 10px rgba(00,00,00,0.45); border: 3px solid transparent; padding:3px; margin-top:20px; \"><legend style=\"color: #069; margin:3px; $widthStr \">$title"; echo ""; print("
'; $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]; return $item; } /** * @param $itemObjArr * @return string */ function makeRssItemString( $itemObjArr ) { $result = ""; foreach( $itemObjArr as $itemObj ): $result .= " http://sz.focus.cn/newscenter/xwsy.html http://images.house.focus.cn/img/newhouselogo.gif 热点新闻-搜狐焦点网深圳站 http://sz.focus.cn/newscenter/xwsy.htmlCopyright 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 = '
内容总结
以上是互联网集市为您收集整理的[原创]替找房方便,将sohu焦点的rss改成全文的全部内容,希望文章能够帮你解决[原创]替找房方便,将sohu焦点的rss改成全文的所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。