(.*?)<\/code><\/pre>/imsu',
create_function('$input', 'return "".htmlentities($input[2])."
";'),
$string);
}
// Truncates the string under the limit specified by the limit parameter.
public static function truncate($string, $limit, $end = '...')
{
// Check if over $limit
if(mb_strlen($string) > $limit) {
// Check if string is only one word
if(preg_match('/\s/', $string)) {
// Append the string specified by the end parameter to the end of the string as it is over the limit.
$truncate = trim(mb_substr($string, 0, mb_strpos($string, ' ', $limit, CHARSET), CHARSET));
} else {
$truncate = trim(mb_substr($string, 0, $limit, CHARSET));
}
$truncate = $truncate.$end;
} else {
$truncate = $string;
}
if(empty($truncate)) {
return '';
}
return $truncate;
}
}