function Html::load
Same name in other branches
- 9 core/lib/Drupal/Component/Utility/Html.php \Drupal\Component\Utility\Html::load()
- 8.9.x core/lib/Drupal/Component/Utility/Html.php \Drupal\Component\Utility\Html::load()
- 10 core/lib/Drupal/Component/Utility/Html.php \Drupal\Component\Utility\Html::load()
Parses an HTML snippet and returns it as a DOM object.
This function loads the body part of a partial HTML document and returns a full \DOMDocument object that represents this document.
Use \Drupal\Component\Utility\Html::serialize() to serialize this \DOMDocument back to a string.
Parameters
string $html: The partial HTML snippet to load. Invalid markup will be corrected on import.
Return value
\DOMDocument A \DOMDocument that represents the loaded HTML snippet.
26 calls to Html::load()
- AssertContentTrait::parse in core/
tests/ Drupal/ KernelTests/ AssertContentTrait.php - Parse content returned from curlExec using DOM and SimpleXML.
- AttributeTest::getXPathResultCount in core/
tests/ Drupal/ Tests/ Core/ Template/ AttributeTest.php - Counts the occurrences of the given XPath query in a given HTML snippet.
- CKEditor5TestTrait::getEditorDataAsDom in core/
modules/ ckeditor5/ tests/ src/ Traits/ CKEditor5TestTrait.php - Gets CKEditor 5 instance data as a PHP DOMDocument.
- EditorFileReference::process in core/
modules/ editor/ src/ Plugin/ Filter/ EditorFileReference.php - Performs the filter processing.
- FieldWebTest::parseContent in core/
modules/ views/ tests/ src/ Functional/ Handler/ FieldWebTest.php - Parse a content and return the html element.
File
-
core/
lib/ Drupal/ Component/ Utility/ Html.php, line 280
Class
- Html
- Provides DOMDocument helpers for parsing and serializing HTML strings.
Namespace
Drupal\Component\UtilityCode
public static function load($html) {
// Instantiate the HTML5 parser, but without the HTML5 namespace being
// added to the DOM document.
$html5 = new HTML5([
'disable_html_ns' => TRUE,
'encoding' => 'UTF-8',
]);
// Attach the provided HTML inside the body. Rely on the HTML5 parser to
// close the body tag.
return $html5->loadHTML('<body>' . $html);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.