Use XML in PHP (config.xml)

xiaoxiao2021-03-06  87

This article implements PHP parsing config.xml configuration files, read the information required to connect to the connection database

Config.xml

-------------------------------------------

192.168.0.1

DBNAME

Postgres

123456

Resolution file Parse.php --------------------------------------------------------------------------------------------------------------------------------------------------------------

Class aminoacid {

Function Aminoacid ($ AA) {

Foreach ($ AA AS $ K => $ V)

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

}

}

Function READDATABASE ($ filename) {

// read the XML Database of Aminoacids

$ DATA = IMPLODE ("", File ($ filename));

$ 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);

// Loop THROUGH THE STRUCTURES

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

IF ($ key == "database") {

$ molranges = $ val;

// Each Contiuous Pair of Array Entries Are the the

// Lower and Upper Range for Each Molecule Definition

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"];

Return New Aminoacid ($ mol);

// Return $ mol;

}

$ db = readdatabase ("config.xml");

/ *

ECHO ("

");

Print_r ($ dB);

ECHO ("");

* /

Foreach ($ DB AS $ Key => $ VAL)

{

Echo ($ VAL-> Host);

}

?>

转载请注明原文地址:https://www.9cbs.com/read-122092.html

New Post(0)