我尝试了几种方法来尝试使其正常工作,但没有运气!
我有一个这样的页面(示例):
<?php
$jj = <<<END
?>
<h1>blah blah</h1>
<p> blah blah blah blah blah blah blah <?php include("file.php"); ?> blah blah</p>
<?php
END;
eval('?>'.$jj.'<?php ');
?>
这导致没有输出什么的,想不出解决办法!
这将不起作用,因为 eval 只需要 PHP 代码(即不被 <?php ?> 标签包围),因此对 eval() 的调用可能会因解析错误而失败。
我建议改用输出缓冲,例如:
<?php
//start output buffering, anything outputted should be stored in a buffer rather than being sent to the browser
ob_start();
?>
<h1>blah blah</h1>
<p> blah blah blah blah blah blah blah <?php include("file.php"); ?> blah blah</p>
<?php
//get contents of buffer and stop buffering
$content = ob_get_clean();
echo $content;
?>