【问题标题】:Getting a Parse error: syntax error, unexpected '}', expecting ',' or '; [closed]出现解析错误:语法错误,意外的 '}',期待 ',' 或 '; [关闭]
【发布时间】:2013-07-24 21:30:17
【问题描述】:

这是我的代码。我是 php 新手,只是尝试使用 Kompozer 编辑页面。当我将站点发布回 ftp 服务器时,此错误突然出现在页面上。奇怪,因为我什至没有碰过这段代码。 (我已经触及下面的代码试图修复它)。任何修复此代码的帮助将不胜感激。

   <?php 
     if(isset($_SESSION["pkg_error"]))
   ?>
      <div class="error_msg_cont">
    <?php 
    foreach($_SESSION["pkg_error"] as $error)
    {
    echo $error. "<br>"
    }
    ?></div>
    <?php 
    if(isset($_SESSION["msg"]))
    {
    echo '<div class="error_msg_cont">'. $_SESSION["msg"] .'<div>'
    }
    ?>

【问题讨论】:

    标签: php syntax-error


    【解决方案1】:

    这两行:

    echo $error. "<br>" }
    
    echo '<div class="error_msg_cont">'. $_SESSION["msg"] .'<div>' }
    

    } 结束前需要一个分号。

    Closing a PHP code block (?&gt;) implies a semicolon,但在 PHP 代码块 (}) 内关闭代码块 不会。

    【讨论】:

    • 我将它们按如下方式放入并得到一个错误解析错误:语法错误,意外的 T_CONSTANT_ENCAPSED_STRING,期望 ']' :echo $error。 "
      "; } 回声'
      '。 $_SESSION["msg"] .'
      '; }
    【解决方案2】:

    你错过了;:

    echo $error. "<br>" }
    

    和

    echo '<div class="error_msg_cont">'. $_SESSION["msg"] .'<div>' }
    

    实际上,错误是不言自明的。

    【讨论】:

    • 我尝试将分号放在 } 之前。它出现了另一个错误:Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ']'
    • 仔细检查其他代码。现在问题出在其他地方。
    猜你喜欢
    • 2012-06-13
    • 2013-07-15
    • 1970-01-01
    • 2013-07-28
    • 2012-07-15
    • 2013-01-11
    • 2012-07-04
    • 1970-01-01
    相关资源
    最近更新 更多