Merge pull request #2610 from mjnaderi/patch-1
character_limiter now works correct for UTF-8 strings
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 206ce55..45e8ae7 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -85,7 +85,7 @@
*/
function character_limiter($str, $n = 500, $end_char = '…')
{
- if (strlen($str) < $n)
+ if (mb_strlen($str) < $n)
{
return $str;
}
@@ -93,7 +93,7 @@
// a bit complicated, but faster than preg_replace with \s+
$str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str));
- if (strlen($str) <= $n)
+ if (mb_strlen($str) <= $n)
{
return $str;
}
@@ -103,10 +103,10 @@
{
$out .= $val.' ';
- if (strlen($out) >= $n)
+ if (mb_strlen($out) >= $n)
{
$out = trim($out);
- return (strlen($out) === strlen($str)) ? $out : $out.$end_char;
+ return (mb_strlen($out) === mb_strlen($str)) ? $out : $out.$end_char;
}
}
}