You are here

public function TruncateHTML::truncateChars in Smart Trim 8

Truncates HTML text by characters.

Parameters

string $html: Text to be updated.

int $limit: Amount of text to allow.

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

Return value

mixed Resulting text.

File

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

Class

TruncateHTML
Class TruncateHTML.

Namespace

Drupal\smart_trim\Truncate

Code

public function truncateChars($html, $limit, $ellipsis = '...') {
  if ($limit <= 0 || $limit >= strlen(strip_tags($html))) {
    return $html;
  }
  $dom = $this
    ->init($html, $limit, $ellipsis);

  // Pass the body node on to be processed.
  $this
    ->domNodeTruncateChars($this->startNode);
  return Html::serialize($dom);
}