Unexecuted PHP code in ob_get_contents
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开发者_如何学JAVA=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?
The <?=
syntax is short tags, and it looks like they're disabled in your php install. You should set short_open_tag
to 1
in the php.ini
file, or you can use ini_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.
精彩评论