lib/blobfolio/common/format.php
public static function excerpt($str='', $args=null) {
		ref\cast::string($str, true);
		ref\sanitize::whitespace($str, 0);
		$str = \strip_tags($str);

		$options = data::parse_args($args, constants::EXCERPT);
		if ($options['length'] < 1) {
			return '';
		}

		$options['unit'] = \strtolower($options['unit']);
		switch (\substr($options['unit'], 0, 4)) {
			case 'char':
				$options['unit'] = 'character';
				break;
			case 'word':
				$options['unit'] = 'word';
				break;
		}

		// Character limit.
		if (
			('character' === $options['unit']) &&
			mb::strlen($str) > $options['length']
		) {
			$str = \trim(mb::substr($str, 0, $options['length'])) . $options['suffix'];
		}
		// Word limit.
		elseif (
			('word' === $options['unit']) &&
			\substr_count($str, ' ') > $options['length'] - 1
		) {
			$str = \explode(' ', $str);
			$str = \array_slice($str, 0, $options['length']);
			$str = \implode(' ', $str) . $options['suffix'];
		}

		return $str;
	}
public static function excerpt($str='', $args=null) {
		ref\cast::string($str, true);
		ref\sanitize::whitespace($str, 0);
		$str = \strip_tags($str);

		$options = data::parse_args($args, constants::EXCERPT);
		if ($options['length'] < 1) {
			return '';
		}

		$options['unit'] = \strtolower($options['unit']);
		switch (\substr($options['unit'], 0, 4)) {
			case 'char':
				$options['unit'] = 'character';
				break;
			case 'word':
				$options['unit'] = 'word';
				break;
		}

		// Character limit.
		if (
			('character' === $options['unit']) &&
			mb::strlen($str) > $options['length']
		) {
			$str = \trim(mb::substr($str, 0, $options['length'])) . $options['suffix'];
		}
		// Word limit.
		elseif (
			('word' === $options['unit']) &&
			\substr_count($str, ' ') > $options['length'] - 1
		) {
			$str = \explode(' ', $str);
			$str = \array_slice($str, 0, $options['length']);
			$str = \implode(' ', $str) . $options['suffix'];
		}

		return $str;
	}
public static function excerpt ( $ str = '' , $ args = null ) { ref \ cast :: string ( $ str , true ) ; ref \ sanitize :: whitespace ( $ str , 0 ) ; $ str = \ strip_tags ( $ str ) ; $ options = data :: parse_args ( $ args , constants :: EXCERPT ) ; if ( $ options [ 'length' ] < 1 ) { return '' ; } $ options [ 'unit' ] = \ strtolower ( $ options [ 'unit' ] ) ; switch ( \ substr ( $ options [ 'unit' ] , 0 , 4 ) ) { case 'char' : $ options [ 'unit' ] = 'character' ; break ; case 'word' : $ options [ 'unit' ] = 'word' ; break ; } // Character limit. if ( ( 'character' === $ options [ 'unit' ] ) && mb :: strlen ( $ str ) > $ options [ 'length' ] ) { $ str = \ trim ( mb :: substr ( $ str , 0 , $ options [ 'length' ] ) ) . $ options [ 'suffix' ] ; } // Word limit. elseif ( ( 'word' === $ options [ 'unit' ] ) && \ substr_count ( $ str , ' ' ) > $ options [ 'length' ] - 1 ) { $ str = \ explode ( ' ' , $ str ) ; $ str = \ array_slice ( $ str , 0 , $ options [ 'length' ] ) ; $ str = \ implode ( ' ' , $ str ) . $ options [ 'suffix' ] ; } return $ str ; }
Generate Text Except

@param string $str String.
@param mixed $args Arguments.

@arg int $length Length limit.
@arg string $unit Unit to examine, "character" or "word".
@arg string $suffix Suffix, e.g. ...

@return string Excerpt.
Generate Text Except