thinkclay/ExpressionEngine-Excerpt-Plugin — Issue #3: clean function
Author: GDmac
Created: 2011-11-22 19:33:26+00:00
State: open

The loop in the clean() method can be trimmed down to an array_slice (was to lazy to fork)

function clean($str, $limit, $indicator)
{
$str = strip_tags($str);

$str = str_replace("\n", ' ', $str);
$str = preg_replace("/\s+/", ' ', $str);
$str = trim($str);
$words = explode(' ', $str);

return trim( implode(' ', array_slice($words, 0, $limit))) . $indicator;
}