Измените HTML и PHP с помощью preg_replace

У меня есть этот HTML / PHP-контент (как строка):

<html> <?php my_class->my_function('test.php', 'value1', 'value2'); <?php my_class->my_function('test2.php', 3); </html> 

То, что my_class-> my_function делает, включает контент в зависимости от отправленных значений.

Он может выглядеть примерно так

 function my_function($file, $value1, $value2) { include $file . $value1 . $value2; } 

Результат my_function должен выводиться вместо вызова функции.

Результат должен быть

 <html> <?php /* Content from file test.php */ echo 'This file is test.php, with value1 and value2'; ?> <?php /* Content from file test2.php */ echo 'This file is test2.php, with value 3'; ?> </html> 

Думаю, мне нужно какое-то preg_replace в сочетании с eval, include или get_file_contents.

Неполный ответ. Это то, что я получил вначале при использовании взрыва. Он работает, но при добавлении нескольких значений в функцию он создает ошибки. Один или два значения, которые он может обрабатывать. Не больше, и для меня это слишком сложно.

 function include_layout2($part, $file = '/index.php') { $url = get_layout2($part, $file); if(file_exists($url)) { return get_include_contents( $url ); } } function get_layout2($part, $file = '/index.php') { $layout_theme = 'default'; $addmod_layout = get_option('addmod_layout'); $layout = $addmod_layout['styles'][$layout_theme][$part]['layout']; $layout = (!empty($layout)) ? $layout : 'default'; $url = TEMPLATEPATH . '/styles/' . $part . '/' . $layout . $file; if(file_exists($url)) { return $url; } } function generate_content($layout = 'index') { $content = include_layout2($layout); $content_a = explode("<?php addmod_include('", $content); $save_for_later = $content; $counter = 0; while(count($content_a) > 1) { $content_a = explode("<?php addmod_include('", $save_for_later); $output = ''; $save_for_later = ''; for($i = 0; $i < sizeof($content_a); $i++) { $content_b = explode("'); ?>", $content_a[$i], 2); if(isset($content_b[0]) && !empty($content_b[0])) { $include_test = include_layout2($content_b[0]); if(isset($include_test)) { $content_b[0] = include_layout2($content_b[0]); } else { $new_layout = explode("addmod_include('", $content_b[0]); $new_file = explode("addmod_include(', '", $content_b[0]); if(isset($new_layout[0]) && isset($new_file[1])) { $content_b[0] = include_layout2($new_layout[0], $new_file[1]); } else { $content_b[0] .= "'); ?>"; } } } $content = implode($content_b); $output .= $content; $save_for_later .= $content; } $counter++; } return $output; } echo generate_content(); 

Не пытайтесь запустить код, потому что он немного зависит от некоторых других вещей.

Я не знаю, ясно ли это, что мне нужно делать?