SpamBlocker

Spam Blocker is a CakePHP Behavior that automatically before after a comment is made. Each comment is tested upon a point system to determine if it should be approved, set to pending (high points), or marked as spam / deleted (low points).

Shorten

If a string is too long, shorten it in the middle, similar to truncation.

Function: shorten()
Category: PHP
Views: 807
Permalink - Tinylink

/**
 * If a string is too long, shorten it in the middle
 * @param string $text
 * @param int $limit
 * @return string
 */
function shorten($text, $limit = 25) {
	if (mb_strlen($text) > $limit) {
		$pre = mb_substr($text, 0, ($limit / 2));	
		$suf = mb_substr($text, -($limit / 2));	
		$text = $pre .' ... '. $suf;
	}
 
	return $text;
}

Return to Snippets