Страница отображает синтаксическую ошибку только на PHP 5.3.1, но хорошо на 5.2.6 - PullRequest
3 голосов
/ 13 марта 2011

У меня есть два сервера разработки, один из которых - PHP версии 5.3.1, который находится на моем главном компьютере разработчика, и на ноутбуке, который служит имитируемым веб-сервером, установлена ​​версия 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>

Я указал неправильную линию в конце моего блока кода.

Ответы [ 3 ]

7 голосов
/ 13 марта 2011

Возможно, одному серверу не нравятся ваши короткие открытые теги : <?.Попробуйте заменить их на <?php.

6 голосов
/ 13 марта 2011

Вы смешиваете <?php и <? теги в своем коде. Я считаю, что вариант <? по умолчанию больше не распознается PHP 5.3.

3 голосов
/ 13 марта 2011

Некоторые блоки PHP в вашем коде запускаются с использованием <? вместо <?php. <? может быть отключено на некоторых серверах. Если вы измените их на <?php, это будет работать.

...