php源代码及代码详细解释如下:
就是加载多了有点慢!不然还挺好用的!确实好玩
- <?php
- //RSS源地址列表数组
- $rssfeed = array("https://www.huhexian.com/feed",
- "http://pfzlcx.cn//rss.php",
- "https://www.iyuren.com/feed",
- "https://www.macrr.com/feed");
- //设置编码为UTF-8
- header('Content-Type:text/html;charset= UTF-8');
- for($i=0;$i<sizeof($rssfeed);$i++){//分解开始
- $buff = "";
- $rss_str="";
- //打开rss地址,并读取,读取失败则中止
- $fp = fopen($rssfeed[$i],"r") or die("can not open $rssfeed");
- while ( !feof($fp) ) {
- $buff .= fgets($fp,4096);
- }
- //关闭文件打开
- fclose($fp);
- //建立一个 XML 解析器
- $parser = xml_parser_create();
- //xml_parser_set_option -- 为指定 XML 解析进行选项设置
- xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
- //xml_parse_into_struct -- 将 XML 数据解析到数组$values中
- xml_parse_into_struct($parser,$buff,$values,$idx);
- //xml_parser_free -- 释放指定的 XML 解析器
- xml_parser_free($parser);
- foreach ($values as $val) {
- $tag = $val["tag"];
- $type = $val["type"];
- $value = $val["value"];
- //标签统一转为小写
- $tag = strtolower($tag);
- if ($tag == "item" && $type == "open"){
- $is_item = 1;
- }else if ($tag == "item" && $type == "close") {
- //构造输出字符串
- $rss_str .= "<a href='".$link."' target=_blank>".$title."</a><br />";
- $is_item = 0;
- }
- //仅读取item标签中的内容
- if($is_item==1){
- if ($tag == "title") {$title = $value;}
- if ($tag == "link") {$link = $value;}
- }
- }
- //输出结果
- echo $rss_str."<br />";
- }
- ?>
php简单获取版:
- <?php
- $xml=simplexml_load_file('http://pfzlcx.cn/rss.php');
- foreach($xml->channel->item as $item){
- echo '<a href="'.$item->link.'">';
- echo $item->title;
- echo '</a>';
- echo '<br/>';
- $des=str_replace(' ','',str_replace(' ','',strip_tags($item->description)));
- $des=str_replace("\n",'',$des);
- $des=str_replace("\r",'',$des);
- echo $des;
- echo '<br/>';
- }
- ?>
版权声明:本文为(演员)原创文章,转载时请注明出处!