Dividir e substituir as coisas pelo PHP e preg_replace em vez de explodir?
Eu tenho um código PHP + HTML como uma string contendo funções. Quero que algumas chamadas de função sejam substituídas pelo conteúdo incluído. Junte muitos arquivos em um.
Breve exemplo - Antes
<html>
<?php myclass->my_function('one', 'two', 'three'); ?>
<h1>Content in between</h1>
<?php myclass->my_function('1', '2'); ?>
</html>
Exemplo breve - Substituindo conteúdo
<html>
<?php run('one', 'two', 'three'); /* Run does include a file */ ?>
<h1>Content in between</h1>
<?php run('1', '2'); /* Run does include a file */ ?>
</html>`
Breve exemplo - Depois
<html>
<?php
/* Start my_function */
echo 'This is the result of my_function one two three';
/* End my_function
?>
<h1>Content in between</h1>
<?php
/* Start my_function */
<?php myclass->my_function('four', 'five', 'six'); ?>
/* End my_function
?>
</html>
Observe que myclass é encontrado no conteúdo incluído. O resultado precisa ser analisado novamente.
Breve exemplo - Depois disso
O conjunto é analisado novamente e substituiu a myclass pelo conteúdo incluído.
<html>
<?php
/* Start my_function */
echo 'This is the result of my_function one two three';
/* End my_function */
?>
<h1>Content in between</h1>
<?php
/* Start my_function */
echo 'four five six';
/* End my_function */
?>
</html>
Eu tentei fazer isso com explodir, mas foi complexo. As duas etapas "Substituindo conteúdo" e "Depois" podem precisar ser executadas de uma só vez.
Olhe para ele como uma corda. O preg_replace pode resolver isso? Quão?