Since: 8.4

final class HTMLDocument extends Document (View source)

Constants

DOCUMENT_POSITION_DISCONNECTED

DOCUMENT_POSITION_PRECEDING

DOCUMENT_POSITION_FOLLOWING

DOCUMENT_POSITION_CONTAINS

DOCUMENT_POSITION_CONTAINED_BY

DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC

Properties

int $nodeType from  Node
string $nodeName from  Node
string $baseURI from  Node
bool $isConnected from  Node
Document|null $ownerDocument from  Node
Node|null $parentNode from  Node
Element|null $parentElement from  Node
Node> $childNodes from  Node
Node|null $firstChild from  Node
Node|null $lastChild from  Node
Node|null $previousSibling from  Node
Node|null $nextSibling from  Node
string|null $nodeValue from  Node
string|null $textContent from  Node
Implementation read-only $implementation from  Document
string $URL from  Document
string $documentURI from  Document
string $characterSet from  Document
string $charset from  Document
string $inputEncoding from  Document
DocumentType|null $doctype from  Document
Element|null $documentElement from  Document
HTMLCollection Since: 8.5
$children from  Document
Element|null $firstElementChild from  Document
Element|null $lastElementChild from  Document
int $childElementCount from  Document
HTMLElement|null $body from  Document
HTMLElement|null $head from  Document
string $title from  Document

Methods

getRootNode(array $options = [])

No description

from  Node
bool
hasChildNodes()

No description

from  Node
void
normalize()

No description

from  Node
cloneNode(bool $deep = false)

No description

from  Node
bool
isEqualNode(Node|null $otherNode)

No description

from  Node
bool
isSameNode(Node|null $otherNode)

No description

from  Node
int
compareDocumentPosition(Node $other)

No description

from  Node
bool
contains(Node|null $other)

No description

from  Node
string|null
lookupPrefix(string|null $namespace)

No description

from  Node
string|null
lookupNamespaceURI(string|null $prefix)

No description

from  Node
bool
isDefaultNamespace(string|null $namespace)

No description

from  Node
insertBefore(Node $node, Node|null $child)

No description

from  Node
appendChild(Node $node)

No description

from  Node
replaceChild(Node $node, Node $child)

No description

from  Node
removeChild(Node $child)

No description

from  Node
int
getLineNo()

No description

from  Node
string
getNodePath()

No description

from  Node
string|false
C14N(bool $exclusive = false, bool $withComments = false, array|null $xpath = null, array|null $nsPrefixes = null)

No description

from  Node
int|false
C14NFile(string $uri, bool $exclusive = false, bool $withComments = false, array|null $xpath = null, array|null $nsPrefixes = null)

No description

from  Node
array
__sleep()

No description

from  Node
void
__wakeup()

No description

from  Node
getElementsByTagName(string $qualifiedName)

No description

from  Document
getElementsByTagNameNS(string|null $namespace, string $localName)

No description

from  Document
createElement(string $localName)

No description

from  Document
createElementNS(string|null $namespace, string $qualifiedName)

No description

from  Document
createTextNode(string $data)

No description

from  Document
createCDATASection(string $data)

No description

from  Document
createComment(string $data)

No description

from  Document
createProcessingInstruction(string $target, string $data)

No description

from  Document
importNode(Node|null $node, bool $deep = false)

No description

from  Document
adoptNode(Node $node)

No description

from  Document
createAttribute(string $localName)

No description

from  Document
createAttributeNS(string|null $namespace, string $qualifiedName)

No description

from  Document
Element|null
getElementById(string $elementId)

No description

from  Document
void
registerNodeClass(string $baseClass, string|null $extendedClass)

No description

from  Document
bool
schemaValidate(string $filename, int $flags = 0)

No description

from  Document
bool
schemaValidateSource(string $source, int $flags = 0)

No description

from  Document
bool
relaxNgValidate(string $filename)

No description

from  Document
bool
relaxNgValidateSource(string $source)

No description

from  Document
void
append(Node|string ...$nodes)

Appends nodes after the last child node

from  Document
void
prepend(Node|string ...$nodes)

Prepends nodes before the first child node

from  Document
void
replaceChildren(Node|string ...$nodes)

Replace children in node

from  Document
importLegacyNode(DOMNode $node, bool $deep = false)

No description

from  Document
Element|null
querySelector(string $selectors)

Returns the first element that matches the CSS selectors

from  Document
querySelectorAll(string $selectors)

No description

from  Document
getElementsByClassName(string $classNames)

No description

from  Document
static HTMLDocument
createEmpty(string $encoding = "UTF-8")

Creates an empty HTML document

static HTMLDocument
createFromFile(string $path, int $options = 0, string|null $overrideEncoding = null)

Parses an HTML document from a file

static HTMLDocument
createFromString(string $source, int $options = 0, string|null $overrideEncoding = null)

Parses an HTML document from a string

string|false
saveXml(Node|null $node = null, int $options = 0)

Serializes the document as an XML string

int|false
saveXmlFile(string $filename, int $options = 0)

Serializes the document as an XML file

string
saveHtml(Node|null $node = null)

Serializes the document as an HTML string

int|false
saveHtmlFile(string $filename)

Serializes the document as an HTML file

Details

Node getRootNode(array $options = [])

No description

Parameters

array $options

Return Value

Node

bool hasChildNodes()

No description

Return Value

bool

void normalize()

No description

Return Value

void

Node cloneNode(bool $deep = false)

No description

Parameters

bool $deep

Return Value

Node

bool isEqualNode(Node|null $otherNode)

No description

Parameters

Node|null $otherNode

Return Value

bool

bool isSameNode(Node|null $otherNode)

No description

Parameters

Node|null $otherNode

Return Value

bool

int compareDocumentPosition(Node $other)

No description

Parameters

Node $other

Return Value

int

bool contains(Node|null $other)

No description

Parameters

Node|null $other

Return Value

bool

string|null lookupPrefix(string|null $namespace)

No description

Parameters

string|null $namespace

Return Value

string|null

string|null lookupNamespaceURI(string|null $prefix)

No description

Parameters

string|null $prefix

Return Value

string|null

bool isDefaultNamespace(string|null $namespace)

No description

Parameters

string|null $namespace

Return Value

bool

Node insertBefore(Node $node, Node|null $child)

No description

Parameters

Node $node
Node|null $child

Return Value

Node

Node appendChild(Node $node)

No description

Parameters

Node $node

Return Value

Node

Node replaceChild(Node $node, Node $child)

No description

Parameters

Node $node
Node $child

Return Value

Node

Node removeChild(Node $child)

No description

Parameters

Node $child

Return Value

Node

int getLineNo()

No description

Return Value

int

string getNodePath()

No description

Return Value

string

string|false C14N(bool $exclusive = false, bool $withComments = false, array|null $xpath = null, array|null $nsPrefixes = null)

No description

Parameters

bool $exclusive
bool $withComments
array|null $xpath
array|null $nsPrefixes

Return Value

string|false

int|false C14NFile(string $uri, bool $exclusive = false, bool $withComments = false, array|null $xpath = null, array|null $nsPrefixes = null)

No description

Parameters

string $uri
bool $exclusive
bool $withComments
array|null $xpath
array|null $nsPrefixes

Return Value

int|false

array __sleep()

No description

Return Value

array

void __wakeup()

No description

Return Value

void

HTMLCollection getElementsByTagName(string $qualifiedName)

No description

Parameters

string $qualifiedName

Return Value

HTMLCollection

HTMLCollection getElementsByTagNameNS(string|null $namespace, string $localName)

No description

Parameters

string|null $namespace
string $localName

Return Value

HTMLCollection

Element createElement(string $localName)

No description

Parameters

string $localName

Return Value

Element

Element createElementNS(string|null $namespace, string $qualifiedName)

No description

Parameters

string|null $namespace
string $qualifiedName

Return Value

Element

DocumentFragment createDocumentFragment()

No description

Return Value

DocumentFragment

Text createTextNode(string $data)

No description

Parameters

string $data

Return Value

Text

CDATASection createCDATASection(string $data)

No description

Parameters

string $data

Return Value

CDATASection

Comment createComment(string $data)

No description

Parameters

string $data

Return Value

Comment

ProcessingInstruction createProcessingInstruction(string $target, string $data)

No description

Parameters

string $target
string $data

Return Value

ProcessingInstruction

Node importNode(Node|null $node, bool $deep = false)

No description

Parameters

Node|null $node
bool $deep

Return Value

Node

Node adoptNode(Node $node)

No description

Parameters

Node $node

Return Value

Node

Attr createAttribute(string $localName)

No description

Parameters

string $localName

Return Value

Attr

Attr createAttributeNS(string|null $namespace, string $qualifiedName)

No description

Parameters

string|null $namespace
string $qualifiedName

Return Value

Attr

Element|null getElementById(string $elementId)

No description

Parameters

string $elementId

Return Value

Element|null

void registerNodeClass(string $baseClass, string|null $extendedClass)

No description

Parameters

string $baseClass
string|null $extendedClass

Return Value

void

bool schemaValidate(string $filename, int $flags = 0)

No description

Parameters

string $filename
int $flags

Return Value

bool

bool schemaValidateSource(string $source, int $flags = 0)

No description

Parameters

string $source
int $flags

Return Value

bool

bool relaxNgValidate(string $filename)

No description

Parameters

string $filename

Return Value

bool

bool relaxNgValidateSource(string $source)

No description

Parameters

string $source

Return Value

bool

void append(Node|string ...$nodes)

Appends nodes after the last child node

Appends one or many nodes to the list of children after the last child node.

Parameters

Node|string ...$nodes

The nodes to append. Strings are automatically converted to text nodes.

Return Value

void

No value is returned.

void prepend(Node|string ...$nodes)

Prepends nodes before the first child node

Prepends one or many nodes to the list of children before the first child node.

Parameters

Node|string ...$nodes

The nodes to prepend. Strings are automatically converted to text nodes.

Return Value

void

No value is returned.

void replaceChildren(Node|string ...$nodes)

Replace children in node

Parameters

Node|string ...$nodes

The nodes replacing the children. Strings are automatically converted to text nodes.

Return Value

void

No value is returned.

Node importLegacyNode(DOMNode $node, bool $deep = false)

No description

Parameters

DOMNode $node
bool $deep

Return Value

Node

Element|null querySelector(string $selectors)

Returns the first element that matches the CSS selectors

Returns the first element that matches the CSS selectors specified in selectors.

Parameters

string $selectors

A string containing one or more CSS selectors.

Return Value

Element|null

Returns the first Dom\Element that matches selectors. Returns null if no element matches.

NodeList querySelectorAll(string $selectors)

No description

Parameters

string $selectors

Return Value

NodeList

HTMLCollection getElementsByClassName(string $classNames)

Since: 8.5

No description

Parameters

string $classNames

Return Value

HTMLCollection

static HTMLDocument createEmpty(string $encoding = "UTF-8")

Creates an empty HTML document

Creates an empty HTML document without any elements.

Parameters

string $encoding

The character encoding of the document, used for serialization when calling the save methods.

Return Value

HTMLDocument

An empty HTML document.

static HTMLDocument createFromFile(string $path, int $options = 0, string|null $overrideEncoding = null)

Parses an HTML document from a file

Parses an HTML document from a file, according to the living standard.

Parameters

string $path

The path to the file to parse.

int $options

Bitwise OR of the libxml option constants. It is also possible to pass Dom\HTML_NO_DEFAULT_NS to disable the use of the HTML namespace and the template element. This should only be used if the implications are properly understood.

string|null $overrideEncoding

The encoding that the document was created in. If not provided, it will attempt to determine the encoding that is most likely used.

Return Value

HTMLDocument

The parsed document as an Dom\HTMLDocument instance.

static HTMLDocument createFromString(string $source, int $options = 0, string|null $overrideEncoding = null)

Parses an HTML document from a string

Parses an HTML document from a string, according to the living standard.

Parameters

string $source

The string containing the HTML to parse.

int $options

Bitwise OR of the libxml option constants. It is also possible to pass Dom\HTML_NO_DEFAULT_NS to disable the use of the HTML namespace and the template element. This should only be used if the implications are properly understood.

string|null $overrideEncoding

The encoding that the document was created in. If not provided, it will attempt to determine the encoding that is most likely used.

Return Value

HTMLDocument

The parsed document as an Dom\HTMLDocument instance.

string|false saveXml(Node|null $node = null, int $options = 0)

Serializes the document as an XML string

Parameters

Node|null $node

The node to serialize. If not provided, the entire document is serialized.

int $options

Additional Options. The LIBXML_NOEMPTYTAG and LIBXML_NOXMLDECL options are supported. Prior to PHP 8.3.0, only the LIBXML_NOEMPTYTAG option is supported.

Return Value

string|false

The serialized XML document string in the current document encoding, or false on failure.

int|false saveXmlFile(string $filename, int $options = 0)

Serializes the document as an XML file

Parameters

string $filename

The path to the file to save to.

int $options

Additional Options. The LIBXML_NOEMPTYTAG and LIBXML_NOXMLDECL options are supported. Prior to PHP 8.3.0, only the LIBXML_NOEMPTYTAG option is supported.

Return Value

int|false

The number of bytes written on success, or false on failure.

string saveHtml(Node|null $node = null)

Serializes the document as an HTML string

Parameters

Node|null $node

The node to serialize. If not provided, the entire document is serialized.

Return Value

string

The serialized HTML document string in the current document encoding.

int|false saveHtmlFile(string $filename)

Serializes the document as an HTML file

Parameters

string $filename

The path to the file to save to.

Return Value

int|false

The number of bytes written on success, or false on failure.