PHP Pear :: Config Management Configuration Information

xiaoxiao2021-03-06  41

PHP Pear :: Config Management Configuration Information

The Config class can manage your configuration files, whether it is stored in an XML file, INI file, php array, or other data resources: 1. Resolve different data formats; 2. Can be skilled Handling Sections, Directives, Comments, Blanks3 you are using. Re-save the configuration information into your favorite format (XML file, INI file, PHP array, or other data resources). The top object config_container: section The following can also include a config_container object; Directive: Does not contain other objects, but there is a pair of data similar to key-value form; Comment: blank: The data format that can be set is: XmlphParrayiniFileApache conf (.conf)

Suppose we have to save employees as the following form jxyuhua jxyuhua at yahoo.com .cn http://www.b2c-battery.co.uk/ The following starts to create it 'IBM', 'Sony' => 'Sony'); $ conf ['Website'] ['UK' ] ['B2C-Battery'] = 'http://www.b2c-battery.co.uk'; $ conf ['Website'] ['UK'] ['Global-Batteries'] =' http: // Www.global-batteries.co.uk ';

$ c = new config (); $ root = & $ c-> Parseconfig ($ conf, 'phparray');

$ storage = & $ root-> getItem ('section', 'storage'); // Delete, then increase, change it to appear $ storage-> removeItem (); $ root-> additem ($ storage); // echo '

'. htmlspecialchars ($ root-> torstring ('XML', array ")))). '';

IF ($ C-> Writeconfig ('D: /TMP/config.xml', 'XML', Array ('Name' => 'Company') === True) {Echo 'Config Written Into D: / TMP /config.xml ';}?> Read configuration file parseconfig ("D: / tmp / member .xml, "XML"); // You can also read configuration information from other places such as: / ** $ conf = array ('db' => Array ('type' => 'mysql', 'Host' => 'LocalHost', 'user' => 'user', 'pass' => 'pass')); $ root = & $ c-> parseconfig ($ conf, 'phparray', array ('name' => 'conf'); * / if (Pear :: Iserror ($ root)) {Die ('Error While Reading Configuration:'. $ root-> getMessage ());} $ settings = $ root-> toArray () PRINTF ('user settings: % s% s/A>', $ settings ['root'] ['Company'] ['member'] ['www'], $ Settings ['root'] ['Company'] ['Name'] ['Name'], $ settings ['root'] ['Company'] ['MEMBER'] ['Email']);?> below Complex, practical: have the following configuration file

< IBM> IBM SONY http://www.b2c-battery.co.uk http://www.global-batteries.co.uk <

/ global-batteries> SQL mysql localhost Mamasam foobar First, let's save it in the XML file: //write.php 'IBM', 'Sony' => 'Sony'); $ Conf ['Website'] ['UK'] ['b2c-battery'] = 'http://www.b2c-battery.co.uk'; $ conf ['Website'] ['UK'] ['Global-Batteries'] =' http: // www .global-batteries.co.uk '; $ c = new config (); $ root = & $ c-> parseconfig ($ conf,' phparray ');

$ storage = & $ root-> getItem ('section', 'storage'); // Delete, then increase, change it to appear $ storage-> removeItem (); $ root-> additem ($ storage); // echo '

'. htmlspecialchars ($ root-> torstring ('XML', array ")))). '';

IF ($ C-> Writeconfig ('D: /TMP/config.xml', 'XML', Array ('Name' => 'Company') === True) {Echo 'Config Written Into D: / TMP /config.xml ';}?> Ok, next is to read this configuration file, suppose we only need the database configuration // read.php parseconfig ('d: /tmp/config.xml', 'XML'); if (Pear :: ISERROR ($ root)) {DIE ($ root-> getMessage ());} // Read the message of the specified selection // I can't read this, I don't know if config problem, but the file for a simple XML structure is ok, will be attached later. Example // $ store = & $ root-> getitem ('section', 'storage'); // Because the above code does not do, so I have to use a stupid approach, so that the volume of large data is not high. . / / Do you have a good solution? Tell me. $ content = $ root-> toarray (); unset ($ root); $ storage = $ content ['root'] ['storage']; unset ($ content); echo ('

 '); Print_R ($ storage); echo ('  '); // This allows you to get a PHP array, and other operations look at yourself. > An example of gettem () read, its data structure is as follows:    localhost   Joe   Secret   db456  


New Post(0)