The Dom\HTMLDocument class

- « Dom\HTMLCollection

- Dom\HTMLDocument::createEmpty »

- PHP Manual
- DOM
- The Dom\HTMLDocument class

# The Dom\HTMLDocument class

(PHP 8 >= 8.4.0)

## Introduction

Represents an HTML document.

## Class synopsis

final class Dom\HTMLDocument extends Dom\Document {
/* Inherited constants */
public const int Dom\Node::DOCUMENT_POSITION_DISCONNECTED = 0x1;
public const int Dom\Node::DOCUMENT_POSITION_PRECEDING = 0x2;
public const int Dom\Node::DOCUMENT_POSITION_FOLLOWING = 0x4;
public const int Dom\Node::DOCUMENT_POSITION_CONTAINS = 0x8;
public const int Dom\Node::DOCUMENT_POSITION_CONTAINED_BY = 0x10;
public const int Dom\Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20;
/* Inherited properties */
public readonly Dom\Implementation $implementation;
public string $URL;
public string $documentURI;
public string $characterSet;
public string $charset;
public string $inputEncoding;
public readonly ?Dom\DocumentType $doctype;
public readonly ?Dom\Element $documentElement;
public readonly ?Dom\Element $firstElementChild;
public readonly ?Dom\Element $lastElementChild;
public readonly int $childElementCount;
public ?Dom\HTMLElement $body;
public readonly ?Dom\HTMLElement $head;
public string $title;
public readonly int $nodeType;
public readonly string $nodeName;
public readonly string $baseURI;
public readonly bool $isConnected;
public readonly ?Dom\Document $ownerDocument;
public readonly ?Dom\Node $parentNode;
public readonly ?Dom\Element $parentElement;
public readonly Dom\NodeList $childNodes;
public readonly ?Dom\Node $firstChild;
public readonly ?Dom\Node $lastChild;
public readonly ?Dom\Node $previousSibling;
public readonly ?Dom\Node $nextSibling;
public ?string $nodeValue;
public ?string $textContent;
/* Methods */
public static createEmpty(string `$encoding` = "UTF-8"): Dom\HTMLDocument
public static createFromFile(string `$path`, int `$options` = 0, ?string `$overrideEncoding` = `null`): Dom\HTMLDocument
public static createFromString(string `$source`, int `$options` = 0, ?string `$overrideEncoding` = `null`): Dom\HTMLDocument
public saveHtml(?Dom\Node `$node` = `null`): string
public saveHtmlFile(string `$filename`): int|false
public saveXml(?Dom\Node `$node` = `null`, int `$options` = 0): string|false
public saveXmlFile(string `$filename`, int `$options` = 0): int|false
/* Inherited methods */
/* Not documented yet */
}

## Notes

> Note: The DOM extension uses UTF-8 encoding when working with methods or properties. The parser methods auto-detect the encoding or allow the caller to specify an encoding.

## Table of Contents

- Dom\HTMLDocument::createEmpty — Creates an empty HTML document
- Dom\HTMLDocument::createFromFile — Parses an HTML document from a file
- Dom\HTMLDocument::createFromString — Parses an HTML document from a string
- Dom\HTMLDocument::saveHtml — Serializes the document as an HTML string
- Dom\HTMLDocument::saveHtmlFile — Serializes the document as an HTML file
- Dom\HTMLDocument::saveXml — Serializes the document as an XML string
- Dom\HTMLDocument::saveXmlFile — Serializes the document as an XML file