本文介绍了Codeigniter PHP短标签不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在遵循基本的Codeigniter教程,并且作者在此view/post_index.php页面中使用了类似的代码

I'm currently following this basic Codeigniter tutorial and the author used this similar code in this view/post_index.php page

if (!isset($posts)){ ?>
    <p> No Post to display </p>
<?php
} else {
    foreach ($posts as $row){
?>
    <h2> <?=$row['title']?> </h2>
        <p> <?=$row['post'] ?></p>

<?php
    }
}
?>

然后我得到一个空白页

<h2> <?=$row['title']?> </h2>
<p> <?=$row['post'] ?></p>

在我的来源中.

但是,当我使用此

    <h2> <?php echo $row['title']?> </h2>
    <p> <?php echo $row['post'] ?></p>

我很好.它显示了我所有的帖子.我正在使用wamp(只是从网站上下载了64bits& Apache 2.4、2.2E版本,除非我看不到它们具有的所有其他4个软件包有什么大不同....)Apache版本:2.2.21
PHP版本:5.3.10

I'm fine. It shows all my posts. I'm running off wamp (just downloaded the 64bits & Apache 2.4, 2.2E Version off the website, except I don't see much difference with all the other 4 packages they have....) with Apache Version : 2.2.21
PHP Version : 5.3.10

这是怎么回事?

谢谢.

推荐答案

这通常意味着您没有启用短标签(大多数PHP< 5.4.0安装会默认将其关闭).您需要检查您的 php.ini 文件.

That normally means you don't have short-tags enabled (most PHP < 5.4.0 installations turn them of by default). You'll need to check your php.ini file.

在启用它们之前,我建议阅读https://softwareengineering.stackexchange.com/questions/151661/is-it-bad-practice-to-use-tag-in-php -使用短标签语法有优缺点.

Before you enable them, I would suggest reading https://softwareengineering.stackexchange.com/questions/151661/is-it-bad-practice-to-use-tag-in-php - there are pros and cons to using the short-tag syntax.

@IMSoP也给出了非常有效的注释:

这篇关于Codeigniter PHP短标签不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 22:14
查看更多