Neos\Eel\Helper\StringHelper::cropAtWord PHP Метод

cropAtWord() публичный Метод

Crop a string to maximumCharacters length, taking words into account, optionally appending suffix if cropping was necessary.
public cropAtWord ( string $string, integer $maximumCharacters, string $suffix = '' ) : string
$string string The input string
$maximumCharacters integer Number of characters where cropping should happen
$suffix string Suffix to be appended if cropping was necessary
Результат string The cropped string
    public function cropAtWord($string, $maximumCharacters, $suffix = '')
    {
        if (UnicodeFunctions::strlen($string) > $maximumCharacters) {
            $iterator = new TextIterator($string, TextIterator::WORD);
            $string = UnicodeFunctions::substr($string, 0, $iterator->preceding($maximumCharacters));
            $string .= $suffix;
        }
        return $string;
    }