Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 4 additions & 33 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,17 @@ class Document
*/
protected DOMDocument $document;

/**
* The XML encoding tag.
*/
protected string $encoding = '<?xml encoding="UTF-8">';

/**
* Initialize the Document instance.
*/
public function __construct(string $html)
{
$this->document = new DOMDocument;

$this->suppress();
$this->document = new DOMDocument(encoding: 'UTF-8');

$this->document->loadHTML(
Str::start($html, $this->encoding),
\LIBXML_HTML_NOIMPLIED | \LIBXML_HTML_NODEFDTD
$html,
LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NOXMLDECL | LIBXML_NOWARNING | LIBXML_NOERROR
);

$this->clear();
}

/**
Expand Down Expand Up @@ -69,27 +60,7 @@ public function xpath(string $expression): DOMNodeList
*/
public function html(): string
{
return trim(substr($this->document->saveHTML(), 23));
}

/**
* Suppress the XML errors.
*/
protected function suppress(): self
{
libxml_use_internal_errors(true);

return $this;
}

/**
* Clear the XML errors.
*/
protected function clear(): self
{
libxml_clear_errors();

return $this;
return trim($this->document->saveHTML());
}

/**
Expand Down
Loading