Truncate a string from the left
@param string $string The string to truncate
@param int $length The length to truncate to
@return string The truncated string
425329
protected function trim_left($string, $length) {
        return '...'.core_text::substr($string, core_text::strlen($string)-$length, $length);
    }
772406
protected function short($string, $length = 200)
    {
        if( strlen( $string ) < $length ) {
            return $string;
        }

        return substr( $string, 0, $length ) .'...';
    }
919278
public function truncate($str, $length, $ellipsis = '...')
    {
        $result = '';
        foreach (preg_split('/\b/U', $str) as $part) {
            if (strlen($result . $part) > $length) {
                $result = rtrim($result) . $ellipsis;
                break;
            } else {
                $result .= $part;
            }
        }

        return $result;
    }
1265848
public static function truncate2(string $str, int $start, int $length = null): string
    {
        if (!$length) {
            $length = $start;
            $start  = 0;
        }

        if (\strlen($str) <= $length) {
            return $str;
        }

        if (\function_exists('mb_substr')) {
            $str = \mb_substr(\strip_tags($str), $start, $length, 'utf-8');
        } else {
            $str = \substr($str, $start, $length) . '...';
        }

        return $str;
    }
910787
protected function trim_center($string, $length) {
        $trimlength = ceil($length/2);
        $start = core_text::substr($string, 0, $trimlength);
        $end = core_text::substr($string, core_text::strlen($string)-$trimlength);
        $string = $start.'...'.$end;
        return $string;
    }
230838
public function tget(string $column, int $length=32) {
		// we get the raw value, truncate it, and escape it afterwards
		return strlen($this->get($column, true)) > $length ? 
			Format::htmlSafe(
				Format::truncate(
					$this->get($column, true),
					$length
				)
			) : 
			$this->get($column);
	}
138383
public static function truncate($text, $length = 100)
    {
        return (self::length($text) > $length)
            ? rtrim(self::substr($text, 0, $length - 3)) . '...'
            : $text;
    }
175587
public static function truncateWords($str, $length, $trailing='...') {
		$words = explode(' ', $str);
		$cutwords = array_slice($words, 0, $length);

		return implode(' ', $cutwords).(count($words) > count($cutwords) ? $trailing:'');
	}
433642
public function toShorten($length = 32, $truncate = false)
        {
            $string = $this->get();

            if (is_bool($length)) {
                $truncate = $length;
                $length = 32;
            } else {
                $length = (int)$length;
            }

            if (strlen($string) > $length) {
                $length - 4;
                $string = substr($string, 0, $length);
                if (!$truncate) {
                    $string = explode(' ', $string);
                    $size = count($string) - 1;
                    if ($size > -1) {
                        $final = '';
                        for ($i = 0; $i < $size; ++$i) {
                            $final .= $string[$i].' ';
                        }
                        $string = $final;
                    }
                }
                $string = trim($string).'...';
            }

            return $string;
        }
47414
public static function getSlice($string, $offset, $length = null)
    {
        if (self::checkMB()) {
            return mb_substr($string, $offset, $length, '8bit');
        }
        if ($length === null) {
            $length = strlen($string);
        }
        return substr($string, $offset, $length);
    }
237376
private static function truncateStr($str, $limit)
    {
        if (strlen($str) > $limit) {
            return substr($str, 0, $limit) . '...';
        }
        return $str;
    }
1369995
public function truncate($value, $length, $replace = '...')
    {
        if (!isset($value)) {
            return null;
        }
        
        return strlen($value) <= $length ? $value : substr($value, 0, $length - strlen($replace)) . $replace;
    }
216536
public static String truncate(String string, int maxBytesLength,
            String appendString) {
        return string.getBytes().length > maxBytesLength ? truncate(string,
                maxBytesLength - appendString.getBytes().length) + appendString
                : string;
    }
829465
public function truncate(int $length = 100, string $append = '...') : Manipulator
    {
        return new static(mb_substr($this->string, 0, $length) . $append);
    }
811431
public function truncateHtml($html, $length, $ellipsis = '...')
    {
        return $this->truncate(html_entity_decode(strip_tags($html), null, 'UTF-8'), $length, $ellipsis);
    }
1128964
public static function substr($string, $from, $length = null)
    {
        if (false === $encoding = mb_detect_encoding($string, null, true)) {
            return substr($string, $from, $length);
        }

        return mb_substr($string, $from, $length, $encoding);
    }
640592
public function shorten($str, $length = 100, $end = '&#8230;')
    {

        if (strlen($str) > $length)
        {
            $str = \substr(trim($str), 0, $length);
            $str = \substr($str, 0, -\strpos(\strrev($str), ' '));
            $str = \trim($str . $end);
        }

        return $str;
    }