This article implements PHP parsing config.xml configuration files, read the information required to connect to the connection database
Config.xml
-------------------------------------------
XML Version = "1.0"?>
database>
configs>
Resolution file Parse.php --------------------------------------------------------------------------------------------------------------------------------------------------------------
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 (" pre>"); * / Foreach ($ DB AS $ Key => $ VAL) { Echo ($ VAL-> Host); } ?>");