ob_get_contents 中未执行的 PHP 代码
我试图通过以下方式捕获我的控制器类(yii 框架)的输出:
ob_start();
$controller->actionView(4);
ob_end_flush();
assertContains('needlestack', ob_get_contents());
ob_clean();
编辑:
似乎与使用有关
令我惊讶的是,输出包含未执行的 PHP 代码!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="en" />
<meta name="description" content="<?=Yii::app()->params['description']?>" />
<link rel="shortcut icon" href="<?= bu('/images/favicon.png') ?>" />
<?= $this->renderPartial('//site/_header_js'); ?>
<link rel="stylesheet" type="text/css" href="/usr/bin/assets/905db112/detailview/styles.css" />
<title><?= CHtml::encode($this->pageTitle); ?></title>
<link type="text/css" rel="stylesheet" href="<?= bu('css/style.css')?> "/>
<link type="text/css" rel="stylesheet" href="<?= bu('css/form.css')?> "/>
<script type="text/javascript" language="javascript" src="<?= bu('js/commonjs.js') ?>"></script>
</head>
<body class="<?= $this->bodyClass ?>">
<div class="wrapper">
<!-- Header -->
<?= $this->renderPartial('//site/_body_header'); ?>
<?= $content; ?>
</div>
<!-- Footer -->
<?= $this->renderPartial('//site/_body_footer'); ?>
<?= $this->renderPartial('//site/_footer_js'); ?>
</body>
</html>
PHP 如何回显未执行的 PHP 代码?我如何获得生成的 HTML?
I'm trying to capture the output of my controller class (yii framework) the following way:
ob_start();
$controller->actionView(4);
ob_end_flush();
assertContains('needlestack', ob_get_contents());
ob_clean();
edit:
Seems it has to do with the use of
To my surprise, the output contains unexecuted PHP code!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="en" />
<meta name="description" content="<?=Yii::app()->params['description']?>" />
<link rel="shortcut icon" href="<?= bu('/images/favicon.png') ?>" />
<?= $this->renderPartial('//site/_header_js'); ?>
<link rel="stylesheet" type="text/css" href="/usr/bin/assets/905db112/detailview/styles.css" />
<title><?= CHtml::encode($this->pageTitle); ?></title>
<link type="text/css" rel="stylesheet" href="<?= bu('css/style.css')?> "/>
<link type="text/css" rel="stylesheet" href="<?= bu('css/form.css')?> "/>
<script type="text/javascript" language="javascript" src="<?= bu('js/commonjs.js') ?>"></script>
</head>
<body class="<?= $this->bodyClass ?>">
<div class="wrapper">
<!-- Header -->
<?= $this->renderPartial('//site/_body_header'); ?>
<?= $content; ?>
</div>
<!-- Footer -->
<?= $this->renderPartial('//site/_body_footer'); ?>
<?= $this->renderPartial('//site/_footer_js'); ?>
</body>
</html>
How could PHP echo unexecuted PHP code? How can I get the resulting HTML?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
语法是短标签,看起来它们在你的 php 安装中被禁用了。您应该在
php.ini
文件中将short_open_tag
设置为1
,或者您可以使用ini_set( "short_open_tag", 1 );
在脚本的顶部。The
<?=
syntax is short tags, and it looks like they're disabled in your php install. You should setshort_open_tag
to1
in thephp.ini
file, or you can useini_set( "short_open_tag", 1 );
at the top of your script.是否启用短开放标记?如果不是,则语法如
和
将不会被解析。
Are short open tags enabled? If they aren't, syntaxes like
<? ... ?>
and<?= ... ?>
won't be parsed.