具有评估代码执行功能的heredoc [英] heredoc with eval code execution
本文介绍了具有评估代码执行功能的heredoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了几种方法来使它正常工作,但是没有运气!
I've tryed a couple of methods to try and get this working but with no luck!
我有一个这样的页面(示例):
I've got a page like this (Example):
<?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 ');
?>
这导致什么都没输出,想不出解决办法!
this causes no output what so ever, can not think of a solution!
推荐答案
这将不起作用,因为eval仅需要PHP代码(即,不被<?php?>标记包围),因此对eval()的调用将可能会因解析错误而失败.
This will not work because eval only expects PHP code (i.e. not surrounded by <?php ?> tags), so the call to eval() will probably fail with a parse error.
我建议改用输出缓冲,例如:
I would suggest using output buffering instead, for example:
<?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;
?>
这篇关于具有评估代码执行功能的heredoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文