You are here

protected function TruncateHTML::countWords in Smart Trim 8

Gets number of words in text.

Parameters

string $text: Text to be counted.

Return value

int Results

2 calls to TruncateHTML::countWords()
TruncateHTML::domNodeTruncateWords in src/Truncate/TruncateHTML.php
Truncates a DOMNode by words.
TruncateHTML::truncateWords in src/Truncate/TruncateHTML.php
Truncates HTML text by words.

File

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

Class

TruncateHTML
Class TruncateHTML.

Namespace

Drupal\smart_trim\Truncate

Code

protected function countWords($text) {
  $words = preg_split("/[\n\r\t ]+/", $text, -1, PREG_SPLIT_NO_EMPTY);
  return count($words);
}