-1

Parse error: syntax error, unexpected T_IF, expecting T_FUNCTION in C:\wamp\www\Exam Creator\cls_FillInTheBlank.php on line 31

我在尝试运行包含 cls_template.php 的 cls_FillInTheBlank.php 时收到此错误。我有两个文件张贴在审查。

cls_FillInTheBlank.php

<?php

    include("cls_template.php");

class fillintheblank{

    function _construct(){
        $cls_blankInput = new template;
        $cls_questionString = new template;
        $cls_fillInTheBlank = new template;
    }

    if(class_exists($cls_blankInput)){
        $cls_blankInput->fillString("<input type='text' name='[qInputName]' id='[qInputId]' value='[qInputValue]' />");
        $cls_blankInput->fillPlaceholderStrings(array("[qInputName]","[qInputId]","[qInputValue]"));
    } else {
        print("\$cls_blankInput not defined.<br>");
    }

    if(class_exists($cls_questionString)){
        $cls_questionString->fillString("");    // to be set later
        $cls_questionString->fillPlaceholderStrings(array("[fib_blank]"));
    } else {
        print("\$cls_questionString not defined.<br>");
    }

    if(class_exists($cls_fillInTheBlank)){
        $cls_fillInTheBlank->fillString("<li>[qFillInTheBlankString]</li>");
        $cls_fillInTheBlank->fillPlaceholderStrings(array("[qFillInTheBlankString]"));
    } else {
        print("\$cls_fillInTheBlank not defined.<br>");
    }

    public function q_fib_buildString($cls_question){
        $i_qID = "";            // @type INTEGER
        $s_html = "";           // @type STRING
        $a_inputs = "";         // @type ARRAY
        $s_innerHTML = "";      // @type STRING
        $s_outerHTML = "";      // @type STRING

        $i_qID = $cls_question->qo_i_id;

        // build the HTML for the blank input
        foreach($cls_question->qo_a_answerSet as $answer){
            $this->cls_blankInput->fillPlaceholderValues(array("qID_".$i_qID,"qID_".$i_qID,$answer["value"]));
            $a_inputs[count($a_inputs)] = $this->cls_blankInput->buildTemplate();
        }

        // build the inner HTML
        $this->cls_questionString->fillString($cls_question->qo_s_string);
        $this->cls_questionString->fillPlaceholderValues($a_inputs);
        $s_innerHTML = $this->cls_blankInput->buildTemplate();


        // build the outer HTML
        $this->cls_fillInTheBlank->fillPlaceholderValues($s_innerHTML);
        $outerHTML =  $this->cls_fillInTheBlank->buildTemplate();

        return $outerHTML;

    }

    public function q_fib_buildString($s_template){
        $s_fib_patterns = array();
        $s_input_blank = "";
        $s_fib_patterns_blank = "[\[fib_blank\]]";

        // array of placeholders 
        $a_fib_patterns['input'] = array();
            // place holder for the name attribute of the input tag
            $a_fib_patterns['attribute']['name'] ="[\[qInputName\]]";
            // place holder for the id attribute of the input tag
            $a_fib_patterns['attribute']['id'] = "[\[qInputId\]]";

        // array of values
        $a_fib_replace['value'] = array();
            // value for the name attribute
            $a_fib_replace['value']['name'] = "qId_".$i_id."[]";
            // value fo the id attribute
            $a_fib_replace['value']['id'] = "qId_".$i_id."[]";

        // build blank input
        $s_input_blank = preg_replace($a_fib_patterns['input'],$a_fib_replace['value'],fillintheblank::$s_blankInput);
        // build question string
        $s_string = preg_replace($s_fib_patterns_blank,$s_input_blank,$s_string);

        /* START CODE FOR TESTING */
//      echo($s_input_blank);   // echo code for the blank inputs
        /* END CODE FOR TESTING */

        // return question string
        return $s_string;

    }

}

?>
4

2 回答 2

6

你基本上得到了这个:

class fillintheblank {
   if (...) {
   }
   if (...) {
   }
}

这是不允许的。类定义具有成员变量和方法定义(即:函数)。您不能将“裸”PHP 代码放在类定义中。你必须将它包装在一个方法中,可能是一个构造函数。

于 2011-03-26T02:48:04.370 回答
0

您的问题是您开始了一个课程,但随后您开始编写通常会在其中的函数体中找到的内容。您需要将第 27-56 行包含在函数定义中。

此外,不相关的是,_construct当您可能指的是__construct. 两个下划线,而不仅仅是一个。

于 2011-03-26T02:48:08.743 回答