Home > php教程 > php手册 > php 读取rss

php 读取rss

WBOY
Release: 2016-06-06 20:01:36
Original
1392 people have browsed it

?php /* 程序:get_xml_array.php 时间:2009-3-20 */ class AminoAcid { function AminoAcid ($aa) { foreach ($aa as $k=$v){ $this-$k = $aa[$k]; } } } /* 函数readDarabase 参数: $file:文件路径。或文件内容,取决于$type $type:1为rss内容,0为rss文

/*

程序:get_xml_array.php

时间:2009-3-20

*/

class AminoAcid {

 

   function AminoAcid ($aa)

   {

       foreach ($aa as $k=>$v){

           $this->$k = $aa[$k];

  }

    }

}

/*

函数readDarabase

参数:

 $file:文件路径。或文件内容,取决于$type

         $type:1为rss内容,0为rss文件

*/

 function readDatabase($file,$tree,$type)

 {

  if($type == 0){

     $data = implode("",file($file));

  }else{

   $data = $file;

  }

    //echo $data;

    $parser = xml_parser_create();

    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);

    xml_parse_into_struct($parser, $data, $values, $tags);

    xml_parser_free($parser);

    foreach ($tags as $key=>$val) {

     if ($key == $tree) {

      $molranges = $val;

      for ($i=0; $i

       $offset = $molranges[$i] + 1;

       $len = $molranges[$i + 1] - $offset;

       $tdb[] = @parseMol(array_slice($values, $offset, $len));

      }

     } else {

      continue;

     }

    }

    return $tdb;

 }

 

 function parseMol($mvalues)

 {

    for ($i=0; $i

     $mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];

    }

    //print_r( new AminoAcid($mol));

    return new AminoAcid($mol);

 }

$tree = "item";

$str = file_get_contents("http://medcl.net/SinaRss.aspx?uid=1562882353");

$db = readDatabase($str,$tree,1);//获得的结果集

echo "

";
<p>print_r($db);</p>
<p>?> </p>



Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template