svn: /pear/peardoc/trunk/en/package/configuration/config/ avail-container/ini-commented.xml avail-container/ini-file.xml
examples/ini-file-read-output.txt examples/ini-file-read.php examples/ini-file-read.txt

From: Date: Thu, 10 Mar 2011 11:08:37 +0000
Subject: svn: /pear/peardoc/trunk/en/package/configuration/config/ avail-container/ini-commented.xml avail-container/ini-file.xml
examples/ini-file-read-output.txt examples/ini-file-read.php examples/ini-file-read.txt
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-12061@lists.php.net to get a copy of this message
cweiske Thu, 10 Mar 2011 11:08:37 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=309070 Log: example to read an ini file Changed paths: U pear/peardoc/trunk/en/package/configuration/config/avail-container/ini-commented.xml U pear/peardoc/trunk/en/package/configuration/config/avail-container/ini-file.xml A pear/peardoc/trunk/en/package/configuration/config/examples/ini-file-read-output.txt A pear/peardoc/trunk/en/package/configuration/config/examples/ini-file-read.php A pear/peardoc/trunk/en/package/configuration/config/examples/ini-file-read.txt Modified: pear/peardoc/trunk/en/package/configuration/config/avail-container/ini-commented.xml =================================================================== --- pear/peardoc/trunk/en/package/configuration/config/avail-container/ini-commented.xml 2011-03-10 09:16:33 UTC (rev 309069) +++ pear/peardoc/trunk/en/package/configuration/config/avail-container/ini-commented.xml 2011-03-10 11:08:37 UTC (rev 309070) @@ -10,9 +10,17 @@ </info> <para> - Parses standard INI files, maintaining comments within the file. + Parses standard INI files, maintaining comments within the file. </para> + <para> + In contrast to + <link linkend="package.configuration.config.avail-container.ini-file">IniFile</link>, + the <literal>IniCommented</literal> container parses the ini file manually using + regular expressions and is slower. + If you only read the file, using IniFile is more appropriate since it's faster. + </para> + <table> <title>Available Options</title> Modified: pear/peardoc/trunk/en/package/configuration/config/avail-container/ini-file.xml =================================================================== --- pear/peardoc/trunk/en/package/configuration/config/avail-container/ini-file.xml 2011-03-10 09:16:33 UTC (rev 309069) +++ pear/peardoc/trunk/en/package/configuration/config/avail-container/ini-file.xml 2011-03-10 11:08:37 UTC (rev 309070) @@ -15,5 +15,44 @@ options are available for this container. </para> - <!-- FIXME: example file, example load, example save --> + + <section> + <info> + <title>Reading a .ini file</title> + </info> + + <example> + <title>Ini file</title> + <programlisting role="ini"> + <xi:include parse="text" + xmlns:xi="http://www.w3.org/2001/XInclude" + href="&package.configuration.config.examples.ini-file-read.txt;" + > + <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback> + </xi:include> + </programlisting> + </example> + + <programlisting role="php"> + <xi:include parse="text" + xmlns:xi="http://www.w3.org/2001/XInclude" + href="&package.configuration.config.examples.ini-file-read.php;" + > + <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback> + </xi:include> + </programlisting> + + <example> + <title>Output</title> + <screen> + <xi:include parse="text" + xmlns:xi="http://www.w3.org/2001/XInclude" + href="&package.configuration.config.examples.ini-file-read-output.txt;" + > + <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback> + </xi:include> + </screen> + </example> + </section> + </section> Added: pear/peardoc/trunk/en/package/configuration/config/examples/ini-file-read-output.txt =================================================================== --- pear/peardoc/trunk/en/package/configuration/config/examples/ini-file-read-output.txt (rev 0) +++ pear/peardoc/trunk/en/package/configuration/config/examples/ini-file-read-output.txt 2011-03-10 11:08:37 UTC (rev 309070) @@ -0,0 +1,4 @@ +Database connection: + Host: db.example.org + User: bloguser + Password: blogpassword Added: pear/peardoc/trunk/en/package/configuration/config/examples/ini-file-read.php =================================================================== --- pear/peardoc/trunk/en/package/configuration/config/examples/ini-file-read.php (rev 0) +++ pear/peardoc/trunk/en/package/configuration/config/examples/ini-file-read.php 2011-03-10 11:08:37 UTC (rev 309070) @@ -0,0 +1,20 @@ +<?php +require_once 'Config.php'; + +$file = dirname(__FILE__) . '/ini-file-read.txt'; + +$conf = new Config(); +$root = $conf->parseConfig($file, 'inifile'); +if (PEAR::isError($root)) { + echo 'Error reading config: ' . $root->getMessage() . "\n"; + exit(1); +} + +$cfg = $root->toArray(); + +echo "Database connection:\n"; +echo ' Host: ' . $cfg['root']['database']['host'] . "\n"; +echo ' User: ' . $cfg['root']['database']['user'] . "\n"; +echo ' Password: ' . $cfg['root']['database']['pass'] . "\n"; + +?> \ No newline at end of file Added: pear/peardoc/trunk/en/package/configuration/config/examples/ini-file-read.txt =================================================================== --- pear/peardoc/trunk/en/package/configuration/config/examples/ini-file-read.txt (rev 0) +++ pear/peardoc/trunk/en/package/configuration/config/examples/ini-file-read.txt 2011-03-10 11:08:37 UTC (rev 309070) @@ -0,0 +1,4 @@ +[database] +host=db.example.org +user=bloguser +pass=blogpassword

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