Fix DOMDocument usage on PHP 8.2
[phorkie.git] / src / phorkie / HtmlParser.php
index b8cd1aff3dbece084445bde9617321aba0ae64bf..8102c69a42c6e45d4c79cefb4773dc7ff7926bb7 100644 (file)
@@ -92,11 +92,14 @@ class HtmlParser
         //$sx = simplexml_load_file($url);
 
         libxml_use_internal_errors(true);
+        $domDoc = new \DOMDocument();
         if ($html === null) {
-            $sx = simplexml_import_dom(\DOMDocument::loadHTMLFile($url));
+            $domDoc->loadHTMLFile($url);
         } else {
-            $sx = simplexml_import_dom(\DOMDocument::loadHTML($html));
+            $domDoc->loadHTML($html);
         }
+        $sx = simplexml_import_dom($domDoc);
+        //FIXME: handle network error
 
         $elems = $sx->xpath('//*[@rel="vcs-git"]');
         $titles = $sx->xpath('/html/head/title');
@@ -173,6 +176,8 @@ class HtmlParser
     public function getHtmlTitle($url)
     {
         libxml_use_internal_errors(true);
+        //allow loading URLs in DOMDocument
+        libxml_disable_entity_loader(false);
         $doc = \DOMDocument::loadHTMLFile($url);
         if ($doc === false) {
             return null;