Utility functions for the PHP DOM extension
Utility functions for the PHP DOM extension., (*1)
$ composer require room11/dom-utils
Gets and sets the default charset used by DOMUtils functions., (*2)
default_charset(string $charSet = ''): string
When the supplied $charSet
is empty, just return the current value. When a new value is supplied, change the
default and return the old one., (*3)
string $charSet
- The new default character set.Loads a HTML string into a DOMDocument object, with error handling and character set normalization., (*4)
domdocument_load_html(string $html, int $options = 0, string $charSet = ''): \DOMDocument
Loads a HTML string into a DOMDocument object, with error handling and character set normalization., (*5)
string $html
- The HTML string to load.int $options
- A bit mask of LibXML options to use when loading the document.string $charSet
- The character set to use when loading the document. Defaults to default_charset()
.Throws a LibXMLFatalErrorException
when loading the document fails., (*6)
Processes a set of HTML strings into DOMDocument objects and invokes a callback for each one., (*7)
domdocument_process_html_docs($htmlStrings, callable $callback, int $options = 0, string $charSet = ''): \DOMDocument
A DOMDocument object will be passed to the first argument of the callback, and an array of LibXMLError objects for the document to the second. The third argument is a boolean which is true if the document could not be loaded. The callback may return boolean false to break the iteration. Any other return value will be ignored., (*8)
string[] $htmlStrings
- An iterable set of HTML strings to process.callable(\DOMDocument, \LibXMLError[], bool) $callback
- The callback to invoke for each document.int $options
- A bit mask of LibXML options to use when loading the documents.string $charSet
- The character set to use when loading the documents. Defaults to default_charset()
.