src/Text.php
public function truncate($length, $substring = '') {
		if ($this->length() <= $length) {
			return new Text($this->string, $this->encoding);
		}

		$substrLen = mb_strlen($substring, $this->encoding);

		if ($this->length() + $substrLen > $length) {
			$length -= $substrLen;
		}

		return $this->substring(0, $length)->append($substring);
	}
public function truncate($length, $substring = '') {
		if ($this->length() <= $length) {
			return new Text($this->string, $this->encoding);
		}

		$substrLen = mb_strlen($substring, $this->encoding);

		if ($this->length() + $substrLen > $length) {
			$length -= $substrLen;
		}

		return $this->substring(0, $length)->append($substring);
	}
public function truncate ( $ length , $ substring = '' ) { if ( $ this -> length ( ) <= $ length ) { return new Text ( $ this -> string , $ this -> encoding ) ; } $ substrLen = mb_strlen ( $ substring , $ this -> encoding ) ; if ( $ this -> length ( ) + $ substrLen > $ length ) { $ length -= $ substrLen ; } return $ this -> substring ( 0 , $ length ) -> append ( $ substring ) ; }
Truncates the string with a substring and ensures it doesn't exceed the given length

@param int $length
@param string $substring
@return Text
Truncates the string with a substring and ensures it doesn t exceed the given length