Ok, not exactly a bug (its documented) but slightly silly behavior if you ask me:
The character_limiter helper normally returns a string larger than the max length specified. This is silly, what if I want to store the text in a limited length VARCHAR field? You could still have some truncation occurring!
Better:
function character_limiter($str, $n = 500, $end_char = '…')
{
if (strlen($str) < $n)
{
return $str;
}
$str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str));
if (strlen($str) <= $n)
{
return $str;
}
$out = "";
$n--; //for end_char
foreach (explode(' ', trim($str)) as $val)
{
if (strlen($out.$val.' ') >= $n)
{
return trim($out).$end_char;
}
$out .= $val.' ';
}
}
