public static function FeedsExXmlUtility::createHtmlDocument in Feeds extensible parsers 7.2
Same name and namespace in other branches
- 7 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 76 - 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 = $options | LIBXML_NOENT | LIBXML_NONET | defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0;
if (version_compare(LIBXML_DOTTED_VERSION, '2.7.0', '>=')) {
$options = $options | LIBXML_PARSEHUGE;
}
$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;
}