src/ORM/FieldType/DBString.php
public function LimitCharactersToClosestWord($limit = 20, $add = '...')
    {
        // Safely convert to plain text
        $value = $this->Plain();

        // Determine if value exceeds limit before limiting characters
        if (mb_strlen($value) <= $limit) {
            return $value;
        }

        // Limit to character limit
        $value = mb_substr($value, 0, $limit);

        // If value exceeds limit, strip punctuation off the end to the last space and apply ellipsis
        $value = preg_replace(
            '/[^\w_]+$/',
            '',
            mb_substr($value, 0, mb_strrpos($value, " "))
        ) . $add;
        return $value;
    }
public function LimitCharactersToClosestWord($limit = 20, $add = '...')
    {
        // Safely convert to plain text
        $value = $this->Plain();

        // Determine if value exceeds limit before limiting characters
        if (mb_strlen($value) <= $limit) {
            return $value;
        }

        // Limit to character limit
        $value = mb_substr($value, 0, $limit);

        // If value exceeds limit, strip punctuation off the end to the last space and apply ellipsis
        $value = preg_replace(
            '/[^\w_]+$/',
            '',
            mb_substr($value, 0, mb_strrpos($value, " "))
        ) . $add;
        return $value;
    }
public function LimitCharactersToClosestWord ( $ limit = 20 , $ add = '...' ) { // Safely convert to plain text $ value = $ this -> Plain ( ) ; // Determine if value exceeds limit before limiting characters if ( mb_strlen ( $ value ) <= $ limit ) { return $ value ; } // Limit to character limit $ value = mb_substr ( $ value , 0 , $ limit ) ; // If value exceeds limit, strip punctuation off the end to the last space and apply ellipsis $ value = preg_replace ( '/[^\w_]+$/' , '' , mb_substr ( $ value , 0 , mb_strrpos ( $ value , " " ) ) ) . $ add ; return $ value ; }
Limit this field's content by a number of characters and truncate
the field to the closest complete word. All HTML tags are stripped
from the field.

@param int $limit Number of characters to limit by
@param string $add Ellipsis to add to the end of truncated string
@return string Plain text value with limited characters
Limit this field s content by a number of characters and truncate the field to the closest complete word . All HTML tags are stripped from the field .