Limit the number of words in a string.

@param  string  $value
@param  int     $words
@param  string  $end
@return string
971530
public static function words($value, $words = 100, $end = '...')
	{
		preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches);

		if ( ! isset($matches[0])) return $value;

		if (strlen($value) == strlen($matches[0])) return $value;

		return rtrim($matches[0]).$end;
	}
1231612
private function parseMath(array $lines, $value, $start, $end)
    {
        return '<p>' . $this->markLine($start, $end) . htmlspecialchars(implode("\n", $lines)) . '</p>';
    }
805977
public static function word(String $str, Int $limit = 100, String $endChar = '...', Bool $stripTags = true, String $encoding = "utf-8") : String
    {
        $str = trim($str);

        if( $stripTags === true )
        {
            $str = strip_tags($str);
        }

        $str = str_replace(["\n","\r","&nbsp;"], " ", $str);

        preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches);

        $match = $matches[0] ?? NULL;

        if( mb_strlen($str, $encoding) === mb_strlen($match, $encoding) )
        {
            $endChar = '';
        }

        return rtrim($match ?? NULL).$endChar;
    }
834848
public static function endsWith(string $string, $values): bool
    {
        foreach ((array) $values as $value) {
            if ($value === '' || substr($string, -strlen($value)) === $value) {
                return true;
            }
        }

        return false;
    }
750784
public static function endsWith($string, $end)
    {
        $l = strlen($end);
        if ($l == 0) {
            return true;
        }
        return substr($string, - $l) === $end;
    }
222238
public function relativeToNow($start, $end, $words = array())
	{
		$this->__construct($start, $end);

		if( empty($words) )
		{
			$words['starting'] = 'Starting';
			$words['ending'] = 'Ending';
			$words['ended'] = 'Ended';
 		}

		if ( $this->tense == 'future' )
		{
			return $words['starting'] . ' ' . $this->start->getRelativeDate();
		}

		if ( $this->tense == 'present' )
		{
			return $words['ending'] . ' ' . $this->end->getRelativeDate();
		}

		if ( $this->tense == 'past' )
		{
			return $words['ended'] . ' ' . $this->end->getRelativeDate();
		}
	}
601437
public function getBetween($content, $start, $end = null)
    {
        return $this->api->getBetween($content, $start, $end);
    }
1370600
public static String slice(final String value, int begin, int end) {
        validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
        return value.substring(begin, end);
    }
619297
public static function words(string $string, int $limite = 20, string $pointer = null): string
    {
        $string = strip_tags(trim($string));

        $arrWords = explode(' ', $string);
        $newWords = implode(' ', array_slice($arrWords, 0, $limite));

        $pointer = (empty($pointer) ? '...' : ' ' . $pointer);
        $result = ($limite < count($arrWords) ? $newWords . $pointer : $string);

        return $result;
    }
11646
public function addWord($word, $value = 1)
    {
        if (isset($this->wordsArray[$word])) {
            $this->wordsArray[$word] += $value;
        } else {
            $this->wordsArray[$word] = $value;
        }
    }
921747
static function endsWith($string, $endsWith, $caseSensitive = true) {
		$len = self::strlen($endsWith);
		if ($caseSensitive) return self::substr($string, -1 * $len) == $endsWith;
		return self::strtolower(self::substr($string, -1 * $len)) == self::strtolower($endsWith);
	}
404311
public static function cut($string, $length, $ender = '…') {
    $length = (int) $length;
    if (mb_strlen($string) > $length) {
      $string = mb_substr($string,0,$length).$ender;
    }
    return $string;
  }
1224779
public function limitWord($string, $limit = 10)
    {
        $words = explode(" ", $string);
        return implode(" ", array_splice($words, 0, $limit));
    }
1048146
def word_ends(self):
        """"""
        if not self.is_tagged(WORDS):
            self.tokenize_words()
        return self.ends(WORDS)
708086
public static function slice($string, $start, $end = null, $encoding = null)
    {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        if ($end === null) {
            $length = Mbstring::strlen($string, $encoding);
        } elseif ($end >= 0 && $end <= $start) {
            return '';
        } elseif ($end < 0) {
            $length = Mbstring::strlen($string, $encoding) + $end - $start;
        } else {
            $length = $end - $start;
        }

        return Mbstring::substr($string, $start, $length, $encoding);
    }
358755
public function setDelimiters($begin, $end)
    {
        $this->beginDelimiter = $begin;

        $this->endDelimiter = $end;

        // for chaining
        return $this;
    }
113727
public function getBetweenReverse($content, $start, $end)
    {
        $endIndex = strrpos($content, $end);
        $startIndex = strrpos($content, $start, -1 * (strlen($content) - $endIndex)) + strlen($start);
        return substr($content, $startIndex, $endIndex - $startIndex);
    }