⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ph5p.php

📁 很棒的在线教学系统
💻 PHP
📖 第 1 页 / 共 5 页
字号:

        /* A character token that is not one of U+0009 CHARACTER TABULATION,
            U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED
            (FF), or U+0020 SPACE
        A start tag token
        An end tag token
        An end-of-file token */
        } elseif(($token['type'] === HTML5::CHARACTR &&
        !preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) ||
        $token['type'] === HTML5::STARTTAG ||
        $token['type'] === HTML5::ENDTAG ||
        $token['type'] === HTML5::EOF) {
            /* Create an HTMLElement node with the tag name html, in the HTML
            namespace. Append it to the Document object. Switch to the main
            phase and reprocess the current token. */
            $html = $this->dom->createElement('html');
            $this->dom->appendChild($html);
            $this->stack[] = $html;

            $this->phase = self::MAIN_PHASE;
            return $this->mainPhase($token);
        }
    }

    private function mainPhase($token) {
        /* Tokens in the main phase must be handled as follows: */

        /* A DOCTYPE token */
        if($token['type'] === HTML5::DOCTYPE) {
            // Parse error. Ignore the token.

        /* A start tag token with the tag name "html" */
        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'html') {
            /* If this start tag token was not the first start tag token, then
            it is a parse error. */

            /* For each attribute on the token, check to see if the attribute
            is already present on the top element of the stack of open elements.
            If it is not, add the attribute and its corresponding value to that
            element. */
            foreach($token['attr'] as $attr) {
                if(!$this->stack[0]->hasAttribute($attr['name'])) {
                    $this->stack[0]->setAttribute($attr['name'], $attr['value']);
                }
            }

        /* An end-of-file token */
        } elseif($token['type'] === HTML5::EOF) {
            /* Generate implied end tags. */
            $this->generateImpliedEndTags();

        /* Anything else. */
        } else {
            /* Depends on the insertion mode: */
            switch($this->mode) {
                case self::BEFOR_HEAD: return $this->beforeHead($token); break;
                case self::IN_HEAD:    return $this->inHead($token); break;
                case self::AFTER_HEAD: return $this->afterHead($token); break;
                case self::IN_BODY:    return $this->inBody($token); break;
                case self::IN_TABLE:   return $this->inTable($token); break;
                case self::IN_CAPTION: return $this->inCaption($token); break;
                case self::IN_CGROUP:  return $this->inColumnGroup($token); break;
                case self::IN_TBODY:   return $this->inTableBody($token); break;
                case self::IN_ROW:     return $this->inRow($token); break;
                case self::IN_CELL:    return $this->inCell($token); break;
                case self::IN_SELECT:  return $this->inSelect($token); break;
                case self::AFTER_BODY: return $this->afterBody($token); break;
                case self::IN_FRAME:   return $this->inFrameset($token); break;
                case self::AFTR_FRAME: return $this->afterFrameset($token); break;
                case self::END_PHASE:  return $this->trailingEndPhase($token); break;
            }
        }
    }

    private function beforeHead($token) {
        /* Handle the token as follows: */

        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
        U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
        or U+0020 SPACE */
        if($token['type'] === HTML5::CHARACTR &&
        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
            /* Append the character to the current node. */
            $this->insertText($token['data']);

        /* A comment token */
        } elseif($token['type'] === HTML5::COMMENT) {
            /* Append a Comment node to the current node with the data attribute
            set to the data given in the comment token. */
            $this->insertComment($token['data']);

        /* A start tag token with the tag name "head" */
        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') {
            /* Create an element for the token, append the new element to the
            current node and push it onto the stack of open elements. */
            $element = $this->insertElement($token);

            /* Set the head element pointer to this new element node. */
            $this->head_pointer = $element;

            /* Change the insertion mode to "in head". */
            $this->mode = self::IN_HEAD;

        /* A start tag token whose tag name is one of: "base", "link", "meta",
        "script", "style", "title". Or an end tag with the tag name "html".
        Or a character token that is not one of U+0009 CHARACTER TABULATION,
        U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
        or U+0020 SPACE. Or any other start tag token */
        } elseif($token['type'] === HTML5::STARTTAG ||
        ($token['type'] === HTML5::ENDTAG && $token['name'] === 'html') ||
        ($token['type'] === HTML5::CHARACTR && !preg_match('/^[\t\n\x0b\x0c ]$/',
        $token['data']))) {
            /* Act as if a start tag token with the tag name "head" and no
            attributes had been seen, then reprocess the current token. */
            $this->beforeHead(array(
                'name' => 'head',
                'type' => HTML5::STARTTAG,
                'attr' => array()
            ));

            return $this->inHead($token);

        /* Any other end tag */
        } elseif($token['type'] === HTML5::ENDTAG) {
            /* Parse error. Ignore the token. */
        }
    }

    private function inHead($token) {
        /* Handle the token as follows: */

        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
        U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
        or U+0020 SPACE.

        THIS DIFFERS FROM THE SPEC: If the current node is either a title, style
        or script element, append the character to the current node regardless
        of its content. */
        if(($token['type'] === HTML5::CHARACTR &&
        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) || (
        $token['type'] === HTML5::CHARACTR && in_array(end($this->stack)->nodeName,
        array('title', 'style', 'script')))) {
            /* Append the character to the current node. */
            $this->insertText($token['data']);

        /* A comment token */
        } elseif($token['type'] === HTML5::COMMENT) {
            /* Append a Comment node to the current node with the data attribute
            set to the data given in the comment token. */
            $this->insertComment($token['data']);

        } elseif($token['type'] === HTML5::ENDTAG &&
        in_array($token['name'], array('title', 'style', 'script'))) {
            array_pop($this->stack);
            return HTML5::PCDATA;

        /* A start tag with the tag name "title" */
        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'title') {
            /* Create an element for the token and append the new element to the
            node pointed to by the head element pointer, or, if that is null
            (innerHTML case), to the current node. */
            if($this->head_pointer !== null) {
                $element = $this->insertElement($token, false);
                $this->head_pointer->appendChild($element);

            } else {
                $element = $this->insertElement($token);
            }

            /* Switch the tokeniser's content model flag  to the RCDATA state. */
            return HTML5::RCDATA;

        /* A start tag with the tag name "style" */
        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'style') {
            /* Create an element for the token and append the new element to the
            node pointed to by the head element pointer, or, if that is null
            (innerHTML case), to the current node. */
            if($this->head_pointer !== null) {
                $element = $this->insertElement($token, false);
                $this->head_pointer->appendChild($element);

            } else {
                $this->insertElement($token);
            }

            /* Switch the tokeniser's content model flag  to the CDATA state. */
            return HTML5::CDATA;

        /* A start tag with the tag name "script" */
        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'script') {
            /* Create an element for the token. */
            $element = $this->insertElement($token, false);
            $this->head_pointer->appendChild($element);

            /* Switch the tokeniser's content model flag  to the CDATA state. */
            return HTML5::CDATA;

        /* A start tag with the tag name "base", "link", or "meta" */
        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
        array('base', 'link', 'meta'))) {
            /* Create an element for the token and append the new element to the
            node pointed to by the head element pointer, or, if that is null
            (innerHTML case), to the current node. */
            if($this->head_pointer !== null) {
                $element = $this->insertElement($token, false);
                $this->head_pointer->appendChild($element);
                array_pop($this->stack);

            } else {
                $this->insertElement($token);
            }

        /* An end tag with the tag name "head" */
        } elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'head') {
            /* If the current node is a head element, pop the current node off
            the stack of open elements. */
            if($this->head_pointer->isSameNode(end($this->stack))) {
                array_pop($this->stack);

            /* Otherwise, this is a parse error. */
            } else {
                // k
            }

            /* Change the insertion mode to "after head". */
            $this->mode = self::AFTER_HEAD;

        /* A start tag with the tag name "head" or an end tag except "html". */
        } elseif(($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') ||
        ($token['type'] === HTML5::ENDTAG && $token['name'] !== 'html')) {
            // Parse error. Ignore the token.

        /* Anything else */
        } else {
            /* If the current node is a head element, act as if an end tag
            token with the tag name "head" had been seen. */
            if($this->head_pointer->isSameNode(end($this->stack))) {
                $this->inHead(array(
                    'name' => 'head',
                    'type' => HTML5::ENDTAG
                ));

            /* Otherwise, change the insertion mode to "after head". */
            } else {
                $this->mode = self::AFTER_HEAD;
            }

            /* Then, reprocess the current token. */
            return $this->afterHead($token);
        }
    }

    private function afterHead($token) {
        /* Handle the token as follows: */

        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
        U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
        or U+0020 SPACE */
        if($token['type'] === HTML5::CHARACTR &&
        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
            /* Append the character to the current node. */
            $this->insertText($token['data']);

        /* A comment token */
        } elseif($token['type'] === HTML5::COMMENT) {
            /* Append a Comment node to the current node with the data attribute
            set to the data given in the comment token. */
            $this->insertComment($token['data']);

        /* A start tag token with the tag name "body" */
        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'body') {
            /* Insert a body element for the token. */
            $this->insertElement($token);

            /* Change the insertion mode to "in body". */
            $this->mode = self::IN_BODY;

        /* A start tag token with the tag name "frameset" */
        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'frameset') {
            /* Insert a frameset element for the token. */
            $this->insertElement($token);

            /* Change the insertion mode to "in frameset". */
            $this->mode = self::IN_FRAME;

        /* A start tag token whose tag name is one of: "base", "link", "meta",
        "script", "style", "title" */
        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
        array('base', 'link', 'meta', 'script', 'style', 'title'))) {
            /* Parse error. Switch the insertion mode back to "in head" and
            reprocess the token. */
            $this->mode = self::IN_HEAD;
            return $this->inHead($token);

        /* Anything else */
        } else {
            /* Act as if a start tag token with the tag name "body" and no
            attributes had been seen, and then reprocess the current token. */
            $this->afterHead(array(
                'name' => 'body',
                'type' => HTML5::STARTTAG,
                'attr' => array()
            ));

            return $this->inBody($token);
        }
    }

    private function inBody($token) {
        /* Handle the token as follows: */

        switch($token['type']) {
            /* A character token */
            case HTML5::CHARACTR:
                /* Reconstruct the active formatting elements, if any. */
                $this->reconstructActiveFormattingElements();

                /* Append the token's character to the current node. */
                $this->insertText($token['data']);
            break;

            /* A comment token */
            case HTML5::COMMENT:
                /* Append a Comment node to the current node with the data
                attr

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -