heredoc with eval code execution

别来无恙 提交于 2019-12-02 22:31:34

问题


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!


回答1:


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;
?>


来源:https://stackoverflow.com/questions/1264981/heredoc-with-eval-code-execution

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!