我有两个开发服务器,一个是PHP版本5.3.1,它位于我的主开发机器上,而作为模拟网络服务器的笔记本电脑上有PHP 5.2.6版本。
使用PHP 5.2.6版本托管的索引页面将正确显示页面。 PHP版本5.3.1上托管的页面没有。
我收到的错误是:
解析错误:第92行的C:\ xampp \ htdocs \ Greek \ index.php中的语法错误,意外'}'
我已附上以下代码。 (但是,我必须警告你它非常大,而且我找不到简单地附加文件或其他任何东西的方法,所以我最好把所有这些放在这里。很抱歉。)
我已经google了一下,看看之前是否发生了这样的事情,但我似乎找不到任何东西。我以为我会问这里。
但是,我们非常感谢任何帮助或指导。
<?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>
我已经指出了代码块末尾的违规行。
答案 0 :(得分:7)
一台服务器可能不喜欢您的short open tags:<?
。尝试用<?php
替换那些。
答案 1 :(得分:6)
您在代码中混合了<?php
和<?
个标记。我相信PHP 5.3不再识别<?
变体。
答案 2 :(得分:3)
代码中的某些PHP块是使用<?
而不是<?php
启动的。某些服务器上可以禁用<?
。如果您将其更改为<?php
,则可以使用。