public function XmlUtility::createHtmlDocument in Feeds extensible parsers 8
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.
File
- src/
Utility/ XmlUtility.php, line 30
Class
- XmlUtility
- Simple XML helpers.
Namespace
Drupal\feeds_ex\UtilityCode
public 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 = $this
->buildDomDocument();
$options |= LIBXML_NONET;
$options |= defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0;
$options |= defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0;
$success = $document
->loadHTML($source, $options);
if (!$success) {
throw new RuntimeException($this
->t('There was an error parsing the HTML document.'));
}
return $document;
}