dongxixian7803 2013-04-07 21:31
浏览 39
已采纳

Codeigniter 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
    }
}
?>

and I get an empty page with this

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

in my source.

However when I use this

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

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

What is going on?

Thank you.

  • 写回答

2条回答 默认 最新

  • duandui2803 2013-04-07 21:34
    关注

    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.

    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 also makes a very valid note:

    Specifically, you need the short_open_tag option (http://www.php.net/manual/en/ini.core.php#ini.short-open-tag) enabled if using PHP < 5.4. From 5.4 onwards, this setting is still present, but is not needed for the <?= ... ?> case, only the potentially problematic <? ... ?>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入