PHP operation XML for database class _ PHP Tutorial

Source: Internet
Author: User
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 string

Http://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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.