You are here

protected function SpamspanDomTrait::loadHtmlDocument in SpamSpan filter 8

Same name and namespace in other branches
  1. 8.2 src/SpamspanDomTrait.php \Drupal\spamspan\SpamspanDomTrait::loadHtmlDocument()

Load text as DOM Document.

Parameters

string $text: Text to load.

Return value

\DOMDocument DOM Document.

2 calls to SpamspanDomTrait::loadHtmlDocument()
SpamspanDomTrait::processAsDom in src/SpamspanDomTrait.php
Replaces email addresses using DOM and regex.
SpamspanDomTrait::replaceDomNode in src/SpamspanDomTrait.php
Replace DOM node with another one created from text.

File

src/SpamspanDomTrait.php, line 94

Class

SpamspanDomTrait
Trait SpamspanDomTrait.

Namespace

Drupal\spamspan

Code

protected function loadHtmlDocument($text) {
  $document = new \DOMDocument();

  // Replace CRLF with LF, because CR will be encoded as &#13 otherwise.
  $text = str_replace("\r\n", "\n", $text);

  // Ignore warnings with '@' due to unknown HTML5 tags (section, aside, etc).
  @$document
    ->loadHTML('<?xml encoding="UTF-8"><div>' . $text . '</div>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
  return $document;
}