PHP Operation XML for database class _php tutorial

Source: Internet
Author: User
Tags dbase
* Example Read data:
*
* $xml = new XML ("Dbase.xml", ' table ');
*
* $data = $xml->xml_fetch_array ();
*
* echo "
";
*
* Print_r ($DATA);
*

Class XML
{
var $dbase; database, the XML file to read
var $dbname; Database name, top-level element, consistent with database file name
var $dbtable; Data table, node to get
var $parser; Profiler
var $vals; Property
var $index; Index
var $dbtable _array;//node Array
var $array; An array of subordinate nodes
var $result; The 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);
Iterate through the index, filtering out the node name to be evaluated: $dbtable
foreach ($this->index as $key = + $val) {
if ($key = = $this->dbtable) {
Get an array of nodes
$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 an array of arrays specified by the offset and length parameters.
Subordinate array of the nodes taken
$value =array_slice ($this->vals, $offset, $len);
Gets a valid array, merged into the result array
$this->array[]= $this->parseeff ($value);
}
return true;
}
Reads the XML file into and returns a string

http://www.bkjia.com/PHPjc/631415.html www.bkjia.com true http://www.bkjia.com/PHPjc/631415.html techarticle PHP * Example Read 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.