在php7.2里面,如果模板里面使用了if else endif标签的话,类似:
复制代码
1
2
3
4
5
6
7<? if ( $the_query->have_posts() ) : ?> <p>XXXXXXx</p> <? else: ?> <p>XXXXXXx</p> <? endif; ?>
这种模板标签,会报如下的错误提示:
syntax error, unexpected end of file, expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF)
比如我的view模板里面写如下的代码:
复制代码
1
2
3
4
5
6
7
8
9
10<? if ( $the_query->have_posts() ) : ?> <? while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <h2><? the_title(); ?></h2> <div class="entry-content"> <? the_content(); ?> </div> <? wp_reset_postdata(); ?> <? else: ?> <p><? _e( 'Sorry, no posts matched your criteria.' ); ?></p> <? endif; ?>
就会出现这种错误提示:
syntax error, unexpected end of file, expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF)
仔细检查没看到语法提示,这个时候是因为php.ini里面的short_open_tag标签没开启,默认的示关闭的,
在php.ini里面设置short_open_tag = On;
重启php即可。
最后
以上就是潇洒钻石最近收集整理的关于php 7.2 if else endif 模板语法错误提示的处理的全部内容,更多相关php内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复