?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>