You are here

public static function FeedsExXmlUtility::createHtmlDocument in Feeds extensible parsers 7

Same name and namespace in other branches
  1. 7.2 src/Xml/Utility.php \FeedsExXmlUtility::createHtmlDocument()

Creates an HTML document.

Parameters

string $source: The string containing the HTML.

int $options: (optional) Bitwise OR of the libxml option constants. Defaults to 0.

Return value

DOMDocument The newly created DOMDocument.

Throws

RuntimeException Thrown if there is a fatal error parsing the XML.

2 calls to FeedsExXmlUtility::createHtmlDocument()
FeedsExHtml::prepareDocument in src/FeedsExHtml.inc
Prepares the DOM document.
FeedsExQueryPathHtml::prepareDocument in src/FeedsExQueryPathHtml.inc
Prepares the DOM document.

File

src/Xml/Utility.php, line 95
Contains FeedsExXmlUtility.

Class

FeedsExXmlUtility
Simple XML helpers.

Code

public static function createHtmlDocument($source, $options = 0) {

  // Fun hack to force parsing as utf-8.
  $source = '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' . "\n" . $source;
  $document = self::buildDomDocument();

  // Pass in options if available.
  if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
    $options |= LIBXML_NONET;
    $options |= defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0;
    $options |= defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0;
    $success = $document
      ->loadHTML($source, $options);
  }
  else {
    $success = $document
      ->loadHTML($source);
  }
  if (!$success) {
    throw new RuntimeException(t('There was an error parsing the HTML document.'));
  }
  return $document;
}