title: Parsing of nested tags in a file
body: <p>I am wondering - What's the most effective way of parsing something like:</p>
  
  <pre><code>{{HEADER}}
  
  Hello my name is {{NAME}}
  
  {{#CONTENT}}
      This is the content ...
  
      {{#PERSONS}}
  
          &lt;p&gt;My name is {{NAME}}.&lt;/p&gt;
  
      {{/PERSONS}}
  
  {{/CONTENT}}
  
  {{FOOTER}}
  </code></pre>
  
  <p>Of course this is intended to be somewhat of a templating system in the end, so my plan is to create a hashmap to "lay over" the template, as something like this</p>
  
  <pre><code>$hash = array(
      'HEADER' =&gt; 'This is a header',
      'NAME' =&gt; 'David',
      'CONTENT' =&gt; array('PERSONS' =&gt; array(array('NAME' =&gt; 'Heino'), array('NAME' =&gt; 'Sebastian')),
      'FOOTER' =&gt; 'This is the footer'
      );
  </code></pre>
  
  <p>It's worth noticing that the "sections" (the tags that start with #), can be repeated more than once, and i think this is what trips me up ...</p>
  
  <p>Also, any section can contain any number of other sections, and regular tags...</p>
  
  <p>So.. how'd you do it?</p>