ManyProgramUse an XML file as the storage carrier for configuration data. You can use zend_config_xml to easily read data from the xml configuration file. The format is as follows:
Zend_config_xml (filename, section, allowmodifications)
The first parameter is the XML file name, and the second parameter is the node name. Third, I don't need to explain it. The following is not so much nonsense. Let's take a look at the example to better understand it:
XML file ----- test. xml
127.0.0.1
pdo_msyql
localhsot
root
123
<Stag extends = "production">// Use the extends keyword to inherit from the node Production
<Database>
<Host> localhost <Username> root </username>
& Lt; password & gt; 123 & lt;/password & gt;
</Database>
</Stag>
</Config>
The PHP file for reading the data in the XML configuration file is as follows:
$ Filename = "test. xml ";
$ Section = "stag ";
$ Config = new zend_config_xml ($ filename, $ section );
Echo $ config-> webhost;
Echo $ config-> database-> type;
Here, the call is also a nested call of the object. Can we convert it to an array? Of course ~! Zend_config_xml is similar to zend_config_ini. You can also use the toarray () method to convert the read content to an array. The two methods are basically the same. If they are not, you can read the content of the previous section. If they are the same, I will not be embarrassed again.
In addition, when reading a file, the file to be read must be readable and exist, and no exception is thrown.