title: Split and replace things with PHP and preg_replace instead of explode?
body: <p>I have a PHP + HTML code as a string containing functions. I want some function calls to be replaced with included content. Put together many files to one.</p>
  
  <p><strong>Short example - Before</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;?php myclass-&gt;my_function('one', 'two', 'three'); ?&gt;
      &lt;h1&gt;Content in between&lt;/h1&gt;
      &lt;?php myclass-&gt;my_function('1', '2'); ?&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Short example - Replacing content</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;?php run('one', 'two', 'three'); /* Run does include a file */ ?&gt;
      &lt;h1&gt;Content in between&lt;/h1&gt;
      &lt;?php run('1', '2'); /* Run does include a file */ ?&gt;
  &lt;/html&gt;`
  </code></pre>
  
  <p><strong>Short example - After</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;?php
      /* Start my_function */
          echo 'This is the result of my_function one two three';
      /* End my_function
      ?&gt;
      &lt;h1&gt;Content in between&lt;/h1&gt;
      &lt;?php
      /* Start my_function */
          &lt;?php myclass-&gt;my_function('four', 'five', 'six'); ?&gt;
      /* End my_function
      ?&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Notice that myclass is found in the included content. The result needs to be parsed again.</p>
  
  <p><strong>Short example - After that</strong></p>
  
  <p>The whole this is parsed again and it replaced the myclass with included content.</p>
  
  <pre><code>&lt;html&gt;
      &lt;?php
      /* Start my_function */
          echo 'This is the result of my_function one two three';
      /* End my_function */
      ?&gt;
      &lt;h1&gt;Content in between&lt;/h1&gt;
      &lt;?php
      /* Start my_function */
          echo 'four five six';
      /* End my_function */
      ?&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I tried to do this with explode but it went to complex. The two steps "Replacing content" and "After" might need to be done in one move.</p>
  
  <p>Look at it as a string. Can preg_replace solve this? How?</p>