很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,访问帮助中心 /help/reopen-questions 。
我有这个 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 结合使用。
不完整的答案。这是我一开始使用explode时得到的结果。它可以工作,但是当向函数添加多个值时,它会产生错误。它可以处理一两个值。不多了,而且对我来说太复杂了,无法处理。
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();
不要尝试运行该代码,因为它有点依赖于其他一些东西。
不知道这是否让我更清楚我需要做什么?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)