Syntax error, unexpected T
I've followed the tutorial in these YT videos to build a language switcher and bilingual site in PHP (no framework). When I try to test it in WAMP, however, I get the following error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in C:wampwwwskydolllangfrancais.php on line 6
I have found by searching this site that this is often caused by the line above the reported error line, but being new to PHP I can't seem to find anything wrong with the code.
<?php
$lang = array(
'hello' => 'Bonjour',
'goodbye' => 'Au revoir'
);
?>
Anything looks out of place?
Before I got to this point, however, I got other syntax errors in the file init.php, which is the file calling francais.php. Could the error be coming from there? I'll include the code for that as well in case:
<?php
session_start();
$allowed_lang = array('english', 'francais');
if (isset($_GET['lang']) === true && in_array($_GET['lang'], allowed_lang) === true) {
$_SESSION['lang'] = $_GET['lang'];
} else if (isset($_SESSION['lang']) === false) {
$_SESSION['lang'] = 'francais';
}
include 'lang/' . $_SESSION['lang'] . '.php';
?>
Thank you in advance for your help.
if (isset($_GET['lang']) === true && in_array($_GET['lang'], allowed_lang) === true) {
应该:
if (isset($_GET['lang']) === true && in_array($_GET['lang'], $allowed_lang) === true) {
您在allowed_lang
之前忘了放置$
字符
上一篇: 解析错误:语法错误,意外的T
下一篇: 语法错误,意外的T