function filter_dom_load

Parses an HTML snippet and returns it as a DOM object.

This function loads the body part of a partial (X)HTML document and returns a full DOMDocument object that represents this document. You can use filter_dom_serialize() to serialize this DOMDocument back to a XHTML snippet.

Parameters

$text: The partial (X)HTML snippet to load. Invalid markup will be corrected on import.

Return value

A DOMDocument that represents the loaded (X)HTML snippet.

3 calls to filter_dom_load()
_filter_html in drupal/core/modules/filter/filter.module
Provides filtering of input into accepted HTML.
_filter_htmlcorrector in drupal/core/modules/filter/filter.module
Scans the input and makes sure that HTML tags are properly closed.
_filter_html_image_secure_process in drupal/core/modules/filter/filter.module
Process callback for local image filter.

File

drupal/core/modules/filter/filter.module, line 1184
Framework for handling the filtering of content.

Code

function filter_dom_load($text) {
  $dom_document = new DOMDocument();

  // Ignore warnings during HTML soup loading.
  @$dom_document
    ->loadHTML('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $text . '</body></html>');
  return $dom_document;
}