? Php * program: get_xml_array.php time: 2009-3-20 * classAminoAcid {functionAminoAcid ($ aa) {foreach ($ aaas $ k $ v) {$ this-$ k $ aa [$ k] ;}} * function readDarabase parameter: $ file: file path. Or file content, depending on $ type: 1 is rss content, 0 is rss
? Php/* program: get_xml_array.php time: 2009-3-20 */class AminoAcid {function AminoAcid ($ aa) {foreach ($ aa as $ k = $ v) {$ this-$ k = $ aa [$ k] ;}}/* function readDarabase parameter: $ file: file path. Or file content, depending on $ type: 1 is rss content, 0 is rss
/*
Program: get_xml_array.php
Time: 2009-3-20
*/
Class AminoAcid {
Function AminoAcid ($ aa)
{
Foreach ($ aa as $ k =>$ v ){
$ This-> $ k = $ aa [$ k];
}
}
}
/*
Function readDarabase
Parameters:
$ File: file path. Or file content, depending on $ type
$ Type: 1 indicates the rss content, and 0 indicates the rss file.
*/
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 <count ($ molranges); $ I + = 2 ){
$ 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 <count ($ mvalues); $ 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); // obtain the result set.
Echo"
";print_r($db);
?>