PHP语法错误:unexpected 'endif' (T_ENDIF) 问题修复求助
修复PHP中
unexpected 'endif' (T_ENDIF)语法错误 你遇到的这个语法错误其实很好定位——问题出在第二个if语句的结尾符号上。看这段代码:
<?php if( $video_banner ); ?>
这里你用了分号;来结束if的条件判断,但在PHP的替代语法(也就是if...endif这种写法)里,条件后面必须用冒号:,而不是分号。分号会让PHP认为这个if语句已经完全结束了,后面的endif就找不到对应的if结构,直接触发语法错误。
把分号改成冒号就能解决问题,修复后的完整代码如下:
<?php if( have_rows('home-video-slider') ): ?> <?php while( have_rows('home-video-slider') ): the_row(); $video_banner = get_sub_field('video-banner'); ?> <div class="item"> <div class="fm-video-banner"> <?php if( $video_banner ): ?> <img src="<?php echo $video_banner['url']; ?>"/> <?php endif; ?> <a class="popup-youtube fm-play-icon" href="https://www.youtube.com/embed/5ktgB9hlETw"> <span> <i class="fa fa-play" aria-hidden="true"></i> </span> </a> </div> </div> <?php $p++; endwhile; ?> <?php endif; ?>
另外给你个小提醒:使用PHP的替代语法(if: ... endif;、while: ... endwhile;这类)时,一定要记住条件后面用冒号,这样才能和对应的结束标签正确配对,避免这类低级语法错误。
内容的提问来源于stack exchange,提问作者sonu sasankan
相关产品推荐
相关产品推荐

