PHP uses XML for database classes .? Php * example reads data: ** $ xmlnewxml (dbase. xml, table); ** $ data $ xml-xml_fetch_array (); ** echoprestylefont-size: 12px; ** print_r ($ data); * classxml {var $ d
* Example:
*
* $ Xml = new xml ("dbase. xml", 'table ');
*
* $ Data = $ xml-> xml_fetch_array ();
*
* Echo"
";
*
* Print_r ($ data );
*
Class xml
{
Var $ dbase; // database, the XML file to be read
Var $ dbname; // database name, top-level element, consistent with the database file name
Var $ dbtable; // data table, the node to be obtained
Var $ parser; // parser
Var $ vals; // attribute
Var $ index; // index
Var $ dbtable_array; // Node array
Var $ array; // an array of lower-level nodes
Var $ result; // returned result
Var $ querys;
Function xml ($ dbase, $ dbtable)
{
$ This-> dbase = $ dbase;
$ This-> dbname = substr ($ dbase, strrpos ($ dbase, "/") 1,-4 );
$ This-> dbtable = $ dbtable;
$ Data = $ this-> ReadXml ($ this-> dbase );
If (! $ Data ){
Die ("unable to read $ this-> dbname. xml ");
}
$ This-> parser = xml_parser_create ();
Xml_parser_set_option ($ this-> parser, XML_OPTION_CASE_FOLDING, 0 );
Xml_parser_set_option ($ this-> parser, XML_OPTION_SKIP_WHITE, 1 );
Xml_parse_into_struct ($ this-> parser, $ data, $ this-> vals, $ this-> index );
Xml_parser_free ($ this-> parser );
// Retrieve the index and find the node name: $ dbtable
Foreach ($ this-> index as $ key => $ val ){
If ($ key = $ this-> dbtable ){
// Obtain the node array
$ This-> dbtable_array = $ val;
} Else {
Continue;
}
}
For ($ I = 0; $ I <count ($ this-> dbtable_array); $ I = 2 ){
$ Offset = $ this-> dbtable_array [$ I] 1;
$ Len = $ this-> dbtable_array [$ I 1]-$ offset;
// Array_slice () returns a sequence in the array specified by the offset and length parameters.
// The array of lower-level nodes
$ Value = array_slice ($ this-> vals, $ offset, $ len );
// Obtain a valid array and merge it into a result array.
$ This-> array [] = $ this-> parseEFF ($ value );
}
Return true;
}
// Read the XML file and return a stringHttp://www.bkjia.com/PHPjc/631415.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631415.htmlTechArticle? Php * example reads data: ** $ xml = new xml (dbase. xml, 'table'); ** $ data = $ xml-xml_fetch_array (); ** echo pre style = font-size: 12px; ** print_r ($ data ); * class xml {var $ d...