mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-04 15:44:07 +01:00
* [FIX] Fixes #175. Fixed multibyte string truncation issue. Thanks to @TitovLab
This commit is contained in:
@@ -83,17 +83,20 @@ class Html
|
||||
/**
|
||||
* Truncar un texto a una determinada longitud.
|
||||
*
|
||||
* @param string $str con la cadena a truncar
|
||||
* @param int $len con la longitud máxima de la cadena
|
||||
* @param string $text la cadena a truncar
|
||||
* @param int $limit la longitud máxima de la cadena
|
||||
* @param string $ellipsis
|
||||
* @return string con el texto truncado
|
||||
*
|
||||
* @link http://www.pjgalbraith.com/truncating-text-html-with-php/
|
||||
*/
|
||||
public static function truncate($str, $len)
|
||||
public static function truncate($text, $limit, $ellipsis = '...')
|
||||
{
|
||||
$tail = max(0, $len - 10);
|
||||
$truncate = mb_substr($str, 0, $tail);
|
||||
$truncate .= strrev(preg_replace('~^..+?[\s,:]\b|^...~', '...', strrev(mb_substr($str, $tail, $len - $tail))));
|
||||
if (strlen($text) > $limit) {
|
||||
$text = trim(mb_substr($text, 0, $limit)) . $ellipsis;
|
||||
}
|
||||
|
||||
return $truncate;
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user