【问题标题】:Parse error: syntax error unexpected T_CONSTANT_ENCAPSED_STRING [closed]解析错误:语法错误意外 T_CONSTANT_ENCAPSED_STRING [关闭]
【发布时间】:2023-04-09 22:44:01
【问题描述】:

这个字符串有问题

'Require.www' => false

这段代码给了我错误:

>Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\KERNEL-DOCMS\Server.Config.php on line 5

我该如何解决这个问题?它在在线游戏的服务器配置中。

完整代码为:

## URL
$Config['URL'] =
    'Default' 
        'Require.www' => false, // www.example.com
        'SSL.enabled' => true, // https://
        'Server' => '***', // public server
        'Lang' => 'en_US' // GLOBAL.
    ,   
    'Other' => 
        //'example.com' => ['Require.www' => false, 'SSL.enabled' => false, 'Lang' => 'es_ES', 'MySQL' => ['host' => '127.0.0.1','user' => 'root','pass' => '','dbname' => 'cmsdb']]
    ,
    'devPrivateServer' => 'localhost' // private developer server
;

## SQL Server Data
$Config['MySQL'] = 
    'host' => '127.0.0.1',
    'user' => '***',
    'pass' => '***',
    'dbname' => 'do'
;
// Do not tuch the code below this text if yuo do not know what yuo're doing
           define( "DB_DSN", "mysql:host".$Config['MySQL']  ['host'].";dbname".$Config['MySQL']['dbname']."");//this constant will
define ( "DB_USERNAME", $Config['MySQL']["user"] ); //username of database
define ( "DB_PASSWORD", $Config['MySQL']["pass"] ); //username of database
define ( "CLS_PATH", "class" ); //the class path of our project

【问题讨论】:

  • 您没有显示相关代码。提供完整的声明。
  • 在最后一条注释上展开,像这样的错误可以在实际错误之后显示行号,因为上一行末尾缺少符号会导致下一行语法无效。

标签: php mysql arrays


【解决方案1】:

这主要是语法错误。如果要声明一个数组,可以使用array() 或简写[]

$Config['URL'] = array(
    'Default' => array(
        'Require.www' => false, // www.example.com
        'SSL.enabled' => true, // https://
        'Server' => '***', // public server
        'Lang' => 'en_US' // GLOBAL.
    )   
    ,   
    'Other' => ''
        //'example.com' => ['Require.www' => false, 'SSL.enabled' => false, 'Lang' => 'es_ES', 'MySQL' => ['host' => '127.0.0.1','user' => 'root','pass' => '','dbname' => 'cmsdb']]
    ,
    'devPrivateServer' => 'localhost' // private developer server
);

$Config['MySQL'] = array(
    'host' => '127.0.0.1',
    'user' => '***',
    'pass' => '***',
    'dbname' => 'do'
);

【讨论】:

  • 谢谢,错误已修复,但现在出现另一个错误: Parse error: syntax error, unexpected T_DOUBLE_ARROW in C:\xampp\KERNEL-DOCMS\Server.Config.php on line 5 我怎么能修复这个?
  • @Joyfabio 第 5 行?发布您正在使用的当前代码。只需使用此答案并将其应用于您的答案,这应该没有问题
  • 错误总是关于 'Require.www' => false, // www.example.com with this code
  • @Joyfabio 你确定你现在正在使用这个答案吗?这里看起来不错codepad.viper-7.com/0Eqhmv
  • 我错了,它成功了,也许我复制了一些不好的东西
猜你喜欢
  • 1970-01-01
  • 2012-03-10
  • 1970-01-01
  • 2012-11-13
  • 1970-01-01
  • 2014-04-02
  • 2011-10-26
相关资源
最近更新 更多