Skip to content

Commit 8d92409

Browse files
authored
Merge pull request #1032 from kaystrobach/patch-1
[BUGFIX] allow to load unclean html without exception
2 parents 2968370 + 06a9271 commit 8d92409

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/PhpWord/Shared/Html.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ public static function addHtml($element, $html, $fullHTML = false, $preserveWhit
7171
$html = '<body>' . $html . '</body>';
7272
}
7373

74+
//need to remove whitespaces between tags, as loadHTML seems to take those into account
75+
$html = preg_replace('/(\>)\s*(\<)/m', '$1$2', $html);
76+
7477
// Load DOM
7578
libxml_disable_entity_loader(true);
7679
$dom = new \DOMDocument();
7780
$dom->preserveWhiteSpace = $preserveWhiteSpace;
78-
$dom->loadXML($html);
81+
$dom->loadHTML($html, LIBXML_NOWARNING);
7982
self::$xpath = new \DOMXPath($dom);
8083
$node = $dom->getElementsByTagName('body');
8184

0 commit comments

Comments
 (0)