title: Regular Expression to match open and closed custom tags
body: <p>I'm design a custom template parser, and want to complier template 
  content to php code by <code>{php xxx}</code> template syntax. </p>
  
  <p>i try to use </p>
  
  <p><code>preg_replace('/{php\s+([^}]+)*}/', '&lt;?php $1?&gt;', '{php echo 'a' }');</code> it is can be work with single line by <code>{php echo 'a' }</code> to <code>&lt;?php echo 'a' ?&gt;</code></p>
  
  <p>and then change pattern support with multi line</p>
  
  <pre><code>$content = "
  {php print_r([
      'foo' =&gt; 'bar',
  ])}
  ";
  echo preg_replace('/{php\s+([^}]+)*}/', '&lt;?php $1?&gt;', $content);
  </code></pre>
  
  <p>now the question is how to support php function in <code>{php xxx}</code> template syntax. </p>
  
  <p>source template content:</p>
  
  <pre><code>{php echo yii\bootstrap\Nav::widget([
     'options' =&gt; ['class' =&gt; 'navbar-nav'],
      'items' =&gt; array_walk($menu, function($data) {
         return yii\helpers\ArrayHelper::remove($data, 'items');
      }),
  ]); }
  </code></pre>
  
  <p>target php code</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php echo yii\bootstrap\Nav::widget([
     'options' =&gt; ['class' =&gt; 'navbar-nav'],
      'items' =&gt; array_walk($menu, function($data) {
         return yii\helpers\ArrayHelper::remove($data, 'items');
      }),
  ]); ?&gt;
  </code></pre>