/** * Load HTML from file * * @param string $filePath * @param int|null $libXMLExtraOptions * * @return HtmlDomParser */ public function loadHtmlFile($filePath, $libXMLExtraOptions = null) { if (!is_string($filePath)) { throw new InvalidArgumentException(__METHOD__ . ' expects parameter 1 to be string.'); } if (!preg_match("/^https?:\\/\\//i", $filePath) && !file_exists($filePath)) { throw new RuntimeException("File {$filePath} not found"); } try { $html = UTF8::file_get_contents($filePath); } catch (\Exception $e) { throw new RuntimeException("Could not load file {$filePath}"); } if ($html === false) { throw new RuntimeException("Could not load file {$filePath}"); } $this->loadHtml($html, $libXMLExtraOptions); return $this; }