CodeIgniter's Text helper has a ellipsize () method for filtering HTML tags and truncating text. But it is particularly bad for Chinese support, in the use of Chinese is garbled.
Below has the netizen to make the function ellipsize () to carry on the modification, causes it to support the Chinese:
In the CI 2.1.3 version, modify the ci_2.1.3\system\helpers\text_helper.php file
Copy Code code as follows:
function ellipsize ($codepage = ' UTF-8 ',
$str, $max _length, $position = 1, $ellipsis = ' ... ')
{
Strip tags
$str = Trim (Strip_tags ($STR));
Is the string long enough to ellipsize?
if (Mb_strlen ($str, $codepage) <= $max _length)
{
return $str;
}
$beg = mb_substr ($str, 0, floor ($max _length * $position), $codepage);
$position = ($position > 1)? 1: $position;
if ($position = = 1)
{
$end = mb_substr ($str, 0,
-($max _length-mb_strlen ($beg, $codepage)), $codepage);
}
Else
{
$end = Mb_substr ($str,
-($max _length-mb_strlen ($beg, $codepage)), $max _length, $codepage);
}
Return $beg. $ellipsis. $end;
}
This code mainly replaces substr and strlen with Mb_substr and Mb_strlen, which will support the truncation of the Chinese language very well.