HEX
Server: Apache/2.2.15 (CentOS)
System: Linux ip-10-0-2-146.eu-west-1.compute.internal 2.6.32-754.35.1.el6.centos.plus.x86_64 #1 SMP Sat Nov 7 11:33:42 UTC 2020 x86_64
User: root (0)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: /www/exchange0old/exchange/Bin/plugins/modifier.limit_chars.php
<?php
function smarty_modifier_limit_chars($str, $limit = 100, $end_char = NULL, $preserve_words = FALSE)
{
    $end_char = ($end_char === NULL) ? '…' : $end_char;

    $limit = (int) $limit;

    if (trim($str) === '' OR strlen($str) <= $limit)
        return $str;

    if ($limit <= 0)
        return $end_char;

    if ($preserve_words === FALSE)
        return rtrim(substr($str, 0, $limit)).$end_char;

    // Don't preserve words. The limit is considered the top limit.
    // No strings with a length longer than $limit should be returned.
    if ( ! preg_match('/^.{0,'.$limit.'}\s/us', $str, $matches))
        return $end_char;

    return rtrim($matches[0]).((strlen($matches[0]) === strlen($str)) ? '' : $end_char);
}
?>