public function TruncateHTML::truncateWords in Smart Trim 8
Truncates HTML text by words.
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 147 - Contains trim functionality.
Class
- TruncateHTML
- Class TruncateHTML.
Namespace
Drupal\smart_trim\TruncateCode
public function truncateWords($html, $limit, $ellipsis = '...') {
if ($limit <= 0 || $limit >= $this
->countWords(strip_tags($html))) {
return $html;
}
$dom = $this
->init($html, $limit, $ellipsis);
// Pass the body node on to be processed.
$this
->domNodeTruncateWords($this->startNode);
return Html::serialize($dom);
}