cvs: peardoc /en/package/configuration/config intro.xml

From: Date: Thu, 27 Nov 2003 20:23:10 +0000
Subject: cvs: peardoc /en/package/configuration/config intro.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-2016@lists.php.net to get a copy of this message
mj Thu Nov 27 15:23:10 2003 EDT Modified files: /peardoc/en/package/configuration/config intro.xml Log: * Adding XML example Index: peardoc/en/package/configuration/config/intro.xml diff -u peardoc/en/package/configuration/config/intro.xml:1.5 peardoc/en/package/configuration/config/intro.xml:1.6 --- peardoc/en/package/configuration/config/intro.xml:1.5 Thu Nov 27 15:07:37 2003 +++ peardoc/en/package/configuration/config/intro.xml Thu Nov 27 15:23:09 2003 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <refentry id="package.configuration.config.intro"> <refnamediv> <refname>Introduction</refname> @@ -82,6 +82,45 @@ <para> The above example illustrates how <classname>Config</classname> and <classname>Config_Container</classname> can interact. There are other ways. You could have for example first created the Config object and then used <link linkend="package.configuration.config.config.getroot"><function>$config-&gt;getRoot</function></link> to add sections and directives to the returned object reference. </para> + <example> + <title>Reading configuration from an XML file</title> + <programlisting role="php"> + <![CDATA[ +require_once 'Config.php'; + +$conf = new Config; +$root =& $conf->parseConfig('config.xml', 'XML'); + +if (PEAR::isError($root)) { + die('Error while reading configuration: ' . $root->getMessage()); +} + +$settings = $root->toArray(); + +printf('User settings: <a href="%s">%s %s</a>', + $settings['root']['conf']['www'], + $settings['root']['conf']['firstname'], + $settings['root']['conf']['lastname'] + ); + ]]> + </programlisting> + <para> + In this example the XML file <filename>config.xml</filename> + looks like this: + </para> + <programlisting role="xml"> + <![CDATA[ +<?xml version="1.0" encoding="UTF-8"?> + +<conf> + <firstname>John</firstname> + <lastname>Doe</lastname> + + <www>http://example.com/</www> +</conf> + ]]> + </programlisting> + </example> <para>For more information, DevShed has a great <ulink url="http://www.devshed.com/Server_Side/PHP/PHP_Config/">tutorial</ulink> about the Config package.</para> </refsect1> </refentry>

« previous php.pear.doc (#2016) next »