我在以下脚本中遇到以下问题
PHP代码:
$var = file_get_contents('template/default/index.php');
$content1 = str_replace('{php}','<?php',$var);
$content2 = str_replace('{/php}','?>',$content1);
echo $content2;
Run Code Online (Sandbox Code Playgroud)
template/default/index.php代码:
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
{php} echo 'worked'; {/php}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我正在尝试将template/default/index.php中的{php} {/ php}标签转换为propper php标签.这实际上发生了,但PHP代码被注释掉了.浏览器给出了这个回报:
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<!--?php echo 'worked'; ?-->
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决这个问题吗?
它应该是eval'd.而不是回应被替换的内容.虽然我不推荐.