【问题标题】:PHP is reporting errors but i can't find any [duplicate]PHP 报告错误,但我找不到任何 [重复]
【发布时间】:2021-08-27 01:07:25
【问题描述】:

我有一个用codeigniter编码的工作网站,PHP突然开始报错,例如

<?php
    $cats = array('7', '9');
    $this->db->select('*');
    $this->db->from('posts');
    $this->db->where_in('posts.category_id',$cats);
    $this->db->where('is_slider=1');
    $this->db->where('visibility=1');
    $this->db->where('posts.status=1');
    $this->db->where('posts.created_at < CURRENT_TIMESTAMP()');
    $this->db->order_by('created_at', 'DESC');
    $this->db->limit(1);
    $query = $this->db->get();
    if($query->num_rows()){
        $primeras = $query->result();
    }
?>
<?php foreach ($primeras as $primera): ?>
    <div class="single-default-inner-news">
        <div class="news-image">
            <?php
            if($primera->post_type == "post"){
            ?>                                
                <a href="#" class="w-100"><img style="min-width:100%" src="<?= base_url() ?><?php echo $primera->image_big ?>" alt="image"></a>
            <? } ?>
            <?php
                if($primera->post_type == "video"){
            ?>
                <a href="#"><img style="min-width:100%" src="<?php echo $primera->image_url ?>" alt="image"></a>
            <? } ?>
                <a href="<?= base_url() ?><?php echo $primera->title_slug ?>" class="link-overlay"></a>

            <div class="news-content" style="padding-top: 15px; width:100%">
                <h2><a href="<?= base_url() ?><?php echo $primera->title_slug ?>"><?php echo $primera->title ?></a></h2>
                <p><?php echo $primera->summary ?></p>
            </div>
        </div>
    </div>
<?php endforeach; ?>    

这就是错误

消息:语法错误,意外的 'endforeach' (T_ENDFOREACH)

有什么建议吗?

提前致谢

【问题讨论】:

  • &lt;? } ?&gt; -> 确保您在 PHP 中启用了短标签,尝试将其更改为 &lt;?php } ?&gt;
  • 每个if 结束都需要&lt;?php } ?&gt; 而不是&lt;? } ?&gt;。将问题作为TYPO 错误结束
  • 你们说得对,主机去掉了短标签

标签: php sql .htaccess codeigniter


【解决方案1】:

已修复,托管删除了我的 php.ini 中的短标签选项

【讨论】:

    猜你喜欢
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 1970-01-01
    • 2021-11-28
    相关资源
    最近更新 更多