多语言PHP联系表,是否可能?

时间:2017-10-05 09:31:38

标签: php multilingual

我在我的网站上有联系表格。最近我决定使页面多语言。一切正常,但我不知道如何在发送电子邮件后弹出的联系表单消息中实现它。有一个例子,它最初是如何编写的:

if(empty($_POST["userName"])) {
        $output = json_encode(array('type'=>'error', 'text' => '<i class="icon ion-close-round"></i> We are sorry but Your name is too short.'));
        die($output);
    }

我想更改文字“我们很抱歉,但你的名字太短了。”回显我的语言php文件,这是一个例子:

echo htmlspecialchars($lang['warning']);
lang.php文件中的

有:

$lang["warning"] = "We are sorry but Your name is too short.";

请问有什么可能吗?感谢您的任何建议:)

1 个答案:

答案 0 :(得分:1)

简单地连接字符串应该有效:

if(empty($_POST["userName"])) {
    $output = json_encode(array('type'=>'error', 'text' => '<i class="icon ion-close-round"></i> ' . htmlspecialchars($lang['warning'])));
    die($output);
}
相关问题