You are here

protected function TruncateHTML::init in Smart Trim 8

Sets up object for use.

Parameters

string $html: Text to be prepared.

int $limit: Amount of text to return.

string $ellipsis: Characters to use at the end of the text.

Return value

\DOMDocument Prepared DOMDocument to work with.

2 calls to TruncateHTML::init()
TruncateHTML::truncateChars in src/Truncate/TruncateHTML.php
Truncates HTML text by characters.
TruncateHTML::truncateWords in src/Truncate/TruncateHTML.php
Truncates HTML text by words.

File

src/Truncate/TruncateHTML.php, line 94
Contains trim functionality.

Class

TruncateHTML
Class TruncateHTML.

Namespace

Drupal\smart_trim\Truncate

Code

protected function init($html, $limit, $ellipsis) {
  $dom = Html::load(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));

  // The body tag node, our html fragment is automatically wrapped in
  // a <html><body> etc.
  $this->startNode = $dom
    ->getElementsByTagName("body")
    ->item(0);
  $this->limit = $limit;
  $this->ellipsis = $ellipsis;
  $this->charCount = 0;
  $this->wordCount = 0;
  $this->foundBreakpoint = FALSE;
  return $dom;
}