Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 什么';这个if语句有两个其他的错误吗?_Php_If Statement - Fatal编程技术网

Php 什么';这个if语句有两个其他的错误吗?

Php 什么';这个if语句有两个其他的错误吗?,php,if-statement,Php,If Statement,代码如下: <?php if ( $current_language == es-ES ) : ?> <?php next_post_link( '%link', 'Proyecto Siguiente ' . _x( '', 'next post link', 'twentyten' ) . '' ); ?> <?php elseif($current_language == zh-TW) : ?> <?php next_post_link( '%

代码如下:

<?php if ( $current_language == es-ES ) : ?>
 <?php next_post_link( '%link', 'Proyecto Siguiente ' . _x( '', 'next post link', 'twentyten' ) . '' ); ?>
<?php elseif($current_language == zh-TW) : ?>
 <?php next_post_link( '%link', '下一個項目 ' . _x( '', 'next post link', 'twentyten' ) . '' ); ?>
<?php elseif($current_language == zh-CN) : ?>
 <?php next_post_link( '%link', '下一个项目 ' . _x( '', 'next post link', 'twentyten' ) . '' ); ?>
<?php else : ?>
 <?php next_post_link( '%link', 'Next Project ' . _x( '', 'next post link', 'twentyten' ) . '' ); ?>
<?php endif; ?>

出于某种原因,即使lang设置为zh TW(中国传统),我仍然会得到“Proyecto Siguiente”


有什么建议吗?

您没有再次引用正在比较的字符串,因此PHP将它们作为常量(不存在)。它仍然可以工作,因为PHP首先查找名为es es的常量,并将抛出级别E_通知的错误(未定义的常量)。请尝试:


依此类推。

当前语言是否与字符串对应?如果是,则需要引用表达式的右侧,因为当前PHP认为它们是常量。 抛弃速记PHP也是一个好主意,但我不想开始争论

<?php if ( $current_language == "es-ES" ){...

为什么要使用所有这些php打开/关闭标记?为什么不在字符串周围使用引号?总之,这是您的代码,应该可以使用:

<?php
    if ( $current_language == 'es-ES' ) {
        next_post_link( '%link', 'Proyecto Siguiente ' . _x( '', 'next post link', 'twentyten' ) . '' );
    } elseif( $current_language == 'zh-TW' ) {
        next_post_link( '%link', '下一個項目 ' . _x( '', 'next post link', 'twentyten' ) . '' );
    } elseif( $current_language == 'zh-CN' ) {
        next_post_link( '%link', '下一个项目 ' . _x( '', 'next post link', 'twentyten' ) . '' );
    } else {
        next_post_link( '%link', 'Next Project ' . _x( '', 'next post link', 'twentyten' ) . '' );
    }
?>


修复是正确的,但解释是不正确的(或者更确切地说,是不完整的)。@Ignacio Vazquez Abrams我怀疑这一点。谢谢!PHP从版本3开始…@没人好,(我想)我只是在遵循WordPress的编码惯例。@IgnacioVazquezAbrams我刚刚学习了PHP5中引入的语法?反正我一直讨厌GW-BASIC风格的语法。
<?php
    if ( $current_language == 'es-ES' ) {
        next_post_link( '%link', 'Proyecto Siguiente ' . _x( '', 'next post link', 'twentyten' ) . '' );
    } elseif( $current_language == 'zh-TW' ) {
        next_post_link( '%link', '下一個項目 ' . _x( '', 'next post link', 'twentyten' ) . '' );
    } elseif( $current_language == 'zh-CN' ) {
        next_post_link( '%link', '下一个项目 ' . _x( '', 'next post link', 'twentyten' ) . '' );
    } else {
        next_post_link( '%link', 'Next Project ' . _x( '', 'next post link', 'twentyten' ) . '' );
    }
?>