Ec (2); To be used, find one on the website and organize it into a class... & nbsp; & lt ;? Php ** PHP obtains and sets XML nodes for modifying and reading site configuration files * & nbsp; * LIQUAN * eg. get & nbsp; config & nbsp; * $ c & nbsp; new & nbsp; Configuration (config. xml); * echo (& nb script ec (2); script
To use it, find one on the website and organize it into a class ..
/*
* PHP obtains and sets XML nodes for modifying and reading site configuration files
* 2008-4-3
* LIQUAN
* Eg. get config
* $ C = new Configuration (''config. xml '');
* Echo ($ c-> TemplateDirectory ."");
*
* Set config
* $ C = new Configuration (''config. xml '');
* $ C-> TemplateDirectory = ''test '';
* $ C-> save ();
*/
Class Configuration
{
Private $ configFile;
Private $ items = array ();
// Constructor
Function _ construct ($ configFile)
{
$ This-> configFile = $ configFile;
$ This-> parse ();
}
// Get attributes
Function _ get ($ id)
{
Return $ this-> items [$ id];
}
// Set attributes
Function _ set ($ key, $ value)
{
$ This-> $ items [$ key] = $ value;
}
// Parse the XML file and save it to an array
Function parse ()
{
$ Doc = new DOMDocument ();
$ Doc-> load ($ this-> configFile );
$ Cn = $ doc-> getElementsByTagName ('config '');
$ Nodes = $ cn-> item (0)-> getElementsByTagName (''*'');
Foreach ($ nodes as $ node)
{
$ This-> items [$ node-> nodeName] = $ node-> nodeValue;
}
}
// Save the XML file
Function save ()
{
$ Doc = new DOMDocument ();
$ Doc-> formatOutput = true;
$ R = $ doc-> createElement (''config '');
$ Doc-> appendChild ($ r );
Foreach ($ this-> items as $ k => $ v)
{
$ KeyName = $ doc-> createElement ($ k );
$ KeyName-> appendChild ($ doc-> createTextNode ($ v ));
$ R-> appendChild ($ keyName );
}
Copy ($ this-> configFile, $ this-> configFile. ". bak ");
$ Doc-> save ($ this-> configFile );
}
}
?>
</