public static function ellipsizeMiddle($string, $max, $ellipses = '...') {
		$string = trim($string);
		$firstPiece = '';
		$lastPiece = '';

		// don't ellipsize if the string is short enough
		if (strlen($string) <= $max) {
			return $string;
		}
		
		// check if the string is all one giant word
		$hasSpace = strpos($string, ' ');
		
		// the entire string is one word
		if ($hasSpace === false) {
			$firstPiece = substr($string, 0, $max / 2);
			$lastPiece = substr($string, - ($max - strlen($firstPiece)));
		} else {
			
			$lastPiece = substr($string, - ($max / 2));
			$lastPiece = trim($lastPiece);
		
			$lastSpace = strrpos($lastPiece, ' ');
			if ($lastSpace !== false)
				$lastPiece = substr($lastPiece, $lastSpace + 1);
			
			$maxFirst = $max - strlen($lastPiece);
			
			$firstPiece = self::ellipsizeRight($string, $maxFirst, '');
		}
	
		$string = $firstPiece . $ellipses . $lastPiece;
		return $string;
	}
public static function ellipsizeMiddle($string, $max, $ellipses = '...') {
		$string = trim($string);
		$firstPiece = '';
		$lastPiece = '';

		// don't ellipsize if the string is short enough
		if (strlen($string) <= $max) {
			return $string;
		}
		
		// check if the string is all one giant word
		$hasSpace = strpos($string, ' ');
		
		// the entire string is one word
		if ($hasSpace === false) {
			$firstPiece = substr($string, 0, $max / 2);
			$lastPiece = substr($string, - ($max - strlen($firstPiece)));
		} else {
			
			$lastPiece = substr($string, - ($max / 2));
			$lastPiece = trim($lastPiece);
		
			$lastSpace = strrpos($lastPiece, ' ');
			if ($lastSpace !== false)
				$lastPiece = substr($lastPiece, $lastSpace + 1);
			
			$maxFirst = $max - strlen($lastPiece);
			
			$firstPiece = self::ellipsizeRight($string, $maxFirst, '');
		}
	
		$string = $firstPiece . $ellipses . $lastPiece;
		return $string;
	}
public static function ellipsizeMiddle ( $ string , $ max , $ ellipses = '...' ) { $ string = trim ( $ string ) ; $ firstPiece = '' ; $ lastPiece = '' ; // don't ellipsize if the string is short enough if ( strlen ( $ string ) <= $ max ) { return $ string ; } // check if the string is all one giant word $ hasSpace = strpos ( $ string , ' ' ) ; // the entire string is one word if ( $ hasSpace === false ) { $ firstPiece = substr ( $ string , 0 , $ max / 2 ) ; $ lastPiece = substr ( $ string , - ( $ max - strlen ( $ firstPiece ) ) ) ; } else { $ lastPiece = substr ( $ string , - ( $ max / 2 ) ) ; $ lastPiece = trim ( $ lastPiece ) ; $ lastSpace = strrpos ( $ lastPiece , ' ' ) ; if ( $ lastSpace !== false ) $ lastPiece = substr ( $ lastPiece , $ lastSpace + 1 ) ; $ maxFirst = $ max - strlen ( $ lastPiece ) ; $ firstPiece = self :: ellipsizeRight ( $ string , $ maxFirst , '' ) ; } $ string = $ firstPiece . $ ellipses . $ lastPiece ; return $ string ; }
Adds a ellipses to the middle of string and trims down the size

@param string $string
@param int $max
@param string $ellipses [default='...']
@return string
Adds a ellipses to the middle of string and trims down the size