Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Html.php

function 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.

12 calls to Html::load()
EditorFileReference::process in core/modules/editor/src/Plugin/Filter/EditorFileReference.php
Performs the filter processing.
FilterAlign::process in core/modules/filter/src/Plugin/Filter/FilterAlign.php
Performs the filter processing.
FilterCaption::process in core/modules/filter/src/Plugin/Filter/FilterCaption.php
Performs the filter processing.
FilterHtml::filterAttributes in core/modules/filter/src/Plugin/Filter/FilterHtml.php
Provides filtering of tag attributes into accepted HTML.
FilterImageLazyLoad::transformImages in core/modules/filter/src/Plugin/Filter/FilterImageLazyLoad.php
Transform markup of images to include loading="lazy".

... See full list

File

core/lib/Drupal/Component/Utility/Html.php, line 280

Class

Html
Provides DOMDocument helpers for parsing and serializing HTML strings.

Namespace

Drupal\Component\Utility

Code

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);
}
RSS feed
Powered by Drupal