Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing an "advanced" INI file with PHP
    primarykey
    data
    text
    <p>Basically, I would like a simple, easy, one-file way to parse an INI file with "advanced" features, like section inheritance and property nesting, like <a href="http://framework.zend.com/manual/en/zend.config.adapters.ini.html" rel="noreferrer">Zend_Config_Ini</a>.</p> <p>For example:</p> <pre><code>[foo] a = 1 b.a = 2 b.b = 3 b.c = 4 c = 5 [bar : foo] b.b = 17 c = 42 </code></pre> <p>Would parse into</p> <pre><code>array( 'foo'=&gt;array( 'a'=&gt;'1', 'b'=&gt;array( 'a'=&gt;'2', 'b'=&gt;'3', 'c'=&gt;'4' ), 'c'=&gt;'5' ), 'bar'=&gt;array( 'a'=&gt;'1', 'b'=&gt;array( 'a'=&gt;'2', 'b'=&gt;'17', 'c'=&gt;'4' ), 'c'=&gt;'42' ) ) </code></pre> <p>PHP's built-in <code>parse_ini_file</code>, doesn't handle anything other than simple INI's with simple sections and simple keys.</p> <p>My problem with using <code>Zend_Config_Ini</code> is that I would have to include virtually the whole Zend_Config subpackage, and is super-bloated and configurable.</p> <p><strong>Is there a <em>small</em> and <em>simple</em> library available to parse this?<br> If not, is there an <em>easy</em> implementation I'm not seeing?</strong></p> <p>By small and simple, I mean something like the sfYaml of INI files.</p> <p>To my (very inexperienced) eyes, I would have to parse through once with <code>parse_ini_file</code>, then come back and resolve inheritance, then run through each section and expand the keys recursively...</p> <p><strong>UPDATE</strong>: Since this seems to be a popular question, I would like to note that <a href="https://github.com/austinhyde/IniParser" rel="noreferrer">I have a simple class implementing this on GitHub</a>, feel free to send pull requests, issues, etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload