带有 eval 代码执行的heredoc

发布于 2024-08-02 02:30:23 字数 327 浏览 2 评论 0原文

我尝试了几种方法来尝试让它工作,但没有运气!

我有一个像这样的页面(示例):

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

这会导致没有输出,想不出解决方案!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2024-08-09 02:30:23

这不起作用,因为 eval 只需要 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;
?>

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;
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文