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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化