You are here

function entity_embed_dom_load_html in Entity Embed 7.2

Same name and namespace in other branches
  1. 7.3 includes/entity_embed.html.inc \entity_embed_dom_load_html()
  2. 7 includes/entity_embed.html.inc \entity_embed_dom_load_html()

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.

Parameters

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

Return value

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

3 calls to entity_embed_dom_load_html()
entity_embed_filter_parse_from_fields in includes/entity_embed.file_usage.inc
Parse file references from an entity's text fields.
_entity_embed_filter_align in ./entity_embed.module
Implements callback_filter_process().
_entity_embed_render_placeholders in ./entity_embed.module
Implements callback_filter_process().

File

includes/entity_embed.html.inc, line 21
DOM processing functions.

Code

function entity_embed_dom_load_html($html) {
  $document = <<<EOD
<!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>!html</body>
</html>
EOD;

  // PHP's \DOMDocument serialization adds straw whitespace in case the markup
  // of the wrapping document contains newlines, so ensure to remove all
  // newlines before injecting the actual HTML body to process.
  $document = strtr($document, array(
    "\n" => '',
    '!html' => $html,
  ));
  $dom = new \DOMDocument();

  // Ignore warnings during HTML soup loading.
  @$dom
    ->loadHTML($document);
  return $dom;
}