We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 708b689 commit c5944f1Copy full SHA for c5944f1
‎src/Document.php‎
@@ -69,7 +69,14 @@ public function xpath(string $expression): DOMNodeList
69
*/
70
public function html(): string
71
{
72
- return trim(substr($this->document->saveHTML(), 23));
+ $html = $this->document->saveHTML();
73
+
74
+ // Remove XML declaration/comment that libxml2 may add
75
+ // Handles both <?xml encoding="UTF-8"> and any comments libxml2 adds
76
+ $html = preg_replace('/^<\?xml[^>]*>\s*/i', '', $html);
77
+ $html = preg_replace('/^<!--[^>]*-->\s*/', '', $html);
78
79
+ return trim($html);
80
}
81
82
/**
0 commit comments