EventHandler
in
Standard events for HTML5.
This is roughly analogous to a SAX2 or expat-style interface. However, it is tuned specifically for HTML5, according to section 8 of the HTML5 specification.
An event handler receives parser events. For a concrete implementation, see DOMTreeBuilder.
Quirks support in the parser is limited to close-in syntax (malformed tags or attributes). Higher order syntax and semantic issues with a document (e.g. mismatched tags, illegal nesting, etc.) are the responsibility of the event handler implementation.
See HTML5 spec section 8.2.4
Table of Contents
Constants
- DOCTYPE_NONE = 0
- DOCTYPE_PUBLIC = 1
- DOCTYPE_SYSTEM = 2
Methods
- cdata() : mixed
- A CDATA section.
- comment() : mixed
- A comment section (unparsed character data).
- doctype() : mixed
- A doctype declaration.
- endTag() : mixed
- An end-tag.
- eof() : mixed
- Indicates that the document has been entirely processed.
- parseError() : mixed
- Emitted when the parser encounters an error condition.
- processingInstruction() : mixed
- This is a holdover from the XML spec.
- startTag() : int
- A start tag.
- text() : mixed
- A unit of parsed character data.
Constants
DOCTYPE_NONE
public
mixed
DOCTYPE_NONE
= 0
DOCTYPE_PUBLIC
public
mixed
DOCTYPE_PUBLIC
= 1
DOCTYPE_SYSTEM
public
mixed
DOCTYPE_SYSTEM
= 2
Methods
cdata()
A CDATA section.
public
cdata(string $data) : mixed
Parameters
- $data : string
-
The unparsed character data
comment()
A comment section (unparsed character data).
public
comment(mixed $cdata) : mixed
Parameters
- $cdata : mixed
doctype()
A doctype declaration.
public
doctype(string $name[, int $idType = 0 ][, string $id = null ][, bool $quirks = false ]) : mixed
Parameters
- $name : string
-
The name of the root element.
- $idType : int = 0
-
One of DOCTYPE_NONE, DOCTYPE_PUBLIC, or DOCTYPE_SYSTEM
- $id : string = null
-
The identifier. For DOCTYPE_PUBLIC, this is the public ID. If DOCTYPE_SYSTEM, then this is a system ID.
- $quirks : bool = false
-
Indicates whether the builder should enter quirks mode.
endTag()
An end-tag.
public
endTag(mixed $name) : mixed
Parameters
- $name : mixed
eof()
Indicates that the document has been entirely processed.
public
eof() : mixed
parseError()
Emitted when the parser encounters an error condition.
public
parseError(mixed $msg, mixed $line, mixed $col) : mixed
Parameters
- $msg : mixed
- $line : mixed
- $col : mixed
processingInstruction()
This is a holdover from the XML spec.
public
processingInstruction(string $name[, string $data = null ]) : mixed
While user agents don't get PIs, server-side does.
Parameters
- $name : string
-
The name of the processor (e.g. 'php').
- $data : string = null
-
The unparsed data.
startTag()
A start tag.
public
startTag(string $name[, array<string|int, mixed> $attributes = array() ][, bool $selfClosing = false ]) : int
IMPORTANT: The parser watches the return value of this event. If this returns an integer, the parser will switch TEXTMODE patters according to the int.
This is how the Tree Builder can tell the Tokenizer when a certain tag should cause the parser to go into RAW text mode.
The HTML5 standard requires that the builder is the one that initiates this step, and this is the only way short of a circular reference that we can do that.
Example: if a startTag even for a script name is fired, and the startTag()
implementation returns Tokenizer::TEXTMODE_RAW, then the tokenizer will
switch into RAW text mode and consume data until it reaches a closing
script tag.
The textmode is automatically reset to Tokenizer::TEXTMODE_NORMAL when the closing tag is encounter. This behavior may change.
Parameters
- $name : string
-
The tag name.
- $attributes : array<string|int, mixed> = array()
-
An array with all of the tag's attributes.
- $selfClosing : bool = false
-
An indicator of whether or not this tag is self-closing (
).
Return values
int —one of the Tokenizer::TEXTMODE_* constants
text()
A unit of parsed character data.
public
text(mixed $cdata) : mixed
Entities in this text are already decoded.
Parameters
- $cdata : mixed