PHP INCLUDE:语法错误,意外的T_INCLUDE,期待T_CASE或T_DEFAULT或'}'

时间:2015-01-25 19:41:28

标签: php

我正试图改变这个:

switch ($lang){

        case "es":
            include("index_es.php");
            break;
        case "en":
            include("index_en.php");
            break;
        default:
            include("index_en.php");
            break;
    }

到此:

switch ($lang){
            include("languages.php");   
    }

在语言文件中生病了所有caseincludebreak信息。它导致语法错误的代码有什么问题吗?

2 个答案:

答案 0 :(得分:1)

您无法使用include替换case的{​​{1}}语句。

相反,将整个事物switch和所有内容放在包含文件中。

那就是说,一个更好的解决方案,特别是如果你添加更多语言,可能是:

switch {}

答案 1 :(得分:0)

你试过了吗?

$lang_file = 'index_' . $lang . '.php';
include_once( $lang_file );