页面只在PHP 5.3.1上显示语法错误,但在5.2.6上正常。

3

我有两个开发服务器,一个是安装在我的主要开发机器上的PHP版本5.3.1,另一个是模拟Web服务器的笔记本电脑,它上面的PHP版本是5.2.6。

使用PHP 5.2.6版本托管的索引页面可以正确显示页面。但托管在PHP版本5.3.1上的页面则不行。

我遇到了以下错误:

解析错误:C:\xampp\htdocs\Greek\index.php的第92行出现意外的“}”

下方附有代码。(然而,我必须警告你,它非常庞大,我找不到一种简单的方法来附加文件之类的东西,所以最好把全部内容都放在这里。对此我很抱歉。)

我已经谷歌搜索过是否发生过类似的情况,但我似乎找不到任何内容。因此我想在这里求助。

但是任何帮助或指导将不胜感激。

<?php
 include_once( 'admin_dataHandler.php' );

// Lets have a handle on the data connection to the data base.
// The file must be edited so that it's pointing to the correct data base.
 $dataHandler = new DataConnection();

 session_start();   // This connects to the existing session

 $msg = "";
 if ( $_SESSION['question_id'] ){
   $question_id = $_SESSION['question_id'];
 }else{
   $question_id = 1; /* Find first question */
 }
 // Debugging only...
 //echo $question_id;
 $answer = "";
 if ( $_REQUEST['action'] ){
   // an action was requested..
   $action = $_REQUEST['action'];
   if ( $action == "answer" ){
        if ( $_REQUEST['answer'] ){
            $answer = $_REQUEST['answer'];
            if ( $dataHandler->checkGreekWordAnswer( $question_id , $answer ) ){ 
              /* Check to see if the answer was correct? */
              $question_id = $dataHandler->getNextGreekWordQuestion( $question_id ); /* Find next question */
              $answer = "";
              $msg = "correct, moving on to next question.";
              // then navigate to the next word.
            }else{
              $msg = "Incorrect. For help hit the hint button";
            }
        }
    }else if ( $action == "next" ) {
        $qid = $question_id;
        $question_id = $dataHandler->getNextGreekWordQuestion( $question_id );
        if( $question_id == null ){
            $msg = "There are no more questions in this quiz";
            // Keep the user where they're at....
            $question_id = $qid;
        }
    }else if ( $action == "back" ){

        $question_id = $dataHandler->getPreviousGreekWordQuestion( $question_id );
        //echo "Current question id is " .$question_id;
        if( $question_id == null ){
            //echo "Something's wrong here...";
            $msg = "You're at the beggining of the quiz.";
            $question_id = 1;
        }
    }else if ( $action == "hint" ){
        $msg = $dataHandler->getHint( $question_id );
        if( $msg == null ){
            $msg = "There are no hints for this question.  Sorry";
        }
    }
 } 
 $question = $dataHandler->getGreekWordQuestion( $question_id );
 $_SESSION['question_id'] = $question_id;

 /** Build the HTML page that's going to be the front end of the quiz.*/
?><html>
  <head>
    <!-- CSS STUFF HERE....-->
    <link rel="stylesheet" type="text/css" href="layout.css">
    <script type="text/javascript" src="translator.js"></script>
    <title>Welcome to the Greek Quiz</title>
  </head>

  <body>
    <div id="header-block">
        <img>
        Welcome to the Biblical Greek Quiz
  </div>
<? if ( $question_id == -1 ) { ?>
<!-- this needs to be a java scripty pop up 
and this H1 section needs to be in red...-->
    <h1>You win!</h1> 
<? }else{ ?>
    <div id="quiz-section">
    <span class='question'><?php echo $question; ?></span>
    <form action='index.php' method='post'>
      <input type='text' size='20' name='answer' id='greekAnswer' onkeyup="trans(this.id)" value='<? echo $answer; ?>'></input>
      <button type='submit' name='action' value='answer'>Send</button>    
      <button type='submit' name='action' value='next'>Next</button>
      <button type='submit' name='action' value='back'>Back</button>
      <button type='submit' name='action' value='hint'>Get a hint.</button>     
    </form>
    </div>
<?php
} <--------------- THis is the } it's not expecting....
?>
<?php
  if ( $msg != "" ){ ?>
<script language='javascript'>
   alert( "<?php echo $msg; ?>" );
</script>
    <?php
        }
    ?>
  </body>  
</html>

我在我的代码块末尾指出了错误行。

1
尝试考虑使用 PHP 替代控制结构。参见 http://php.net/manual/en/control-structures.alternative-syntax.php。 - slier
3个回答

6

你的一个服务器可能不支持 短标记: <?。尝试将其替换为 <?php


5
你的代码中混合了 <?php<? 标签。我认为 PHP 5.3 默认不再识别 <? 变体。

非常好,非常感谢 :-) 我已经记下了。 - user628985

2

你的代码中有一些 PHP 代码块是使用 <? 而不是 <?php 开始的。在某些服务器上,<? 可能已被禁用。如果你将它们改为 <?php,那么它就可以工作了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接