diff options
author | Mohammad Javad Naderi <mjnaderi@gmail.com> | 2013-08-22 16:03:50 +0200 |
---|---|---|
committer | Mohammad Javad Naderi <mjnaderi@gmail.com> | 2013-08-22 16:03:50 +0200 |
commit | c6f5ed16c6a4a146deb40870781442d0936ac33a (patch) | |
tree | 3a736a3be23dc7b3e470aa43d89152436815f230 /system/helpers | |
parent | 9aebeaf6efa69a63c1518f1c7b0886e510909d29 (diff) |
count number of characters (with mb_strlen) instead of counting number of bytes with strlen
Diffstat (limited to 'system/helpers')
-rw-r--r-- | system/helpers/text_helper.php | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 8dae3be4e..bfbdc2f00 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -85,7 +85,7 @@ if ( ! function_exists('character_limiter')) */ function character_limiter($str, $n = 500, $end_char = '…') { - if (strlen(utf8_decode($str)) < $n) + if (mb_strlen($str) < $n) { return $str; } @@ -93,7 +93,7 @@ if ( ! function_exists('character_limiter')) // 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(utf8_decode($str)) <= $n) + if (mb_strlen($str) <= $n) { return $str; } @@ -103,10 +103,10 @@ if ( ! function_exists('character_limiter')) { $out .= $val.' '; - if (strlen(utf8_decode($out)) >= $n) + if (mb_strlen($out) >= $n) { $out = trim($out); - return (strlen(utf8_decode($out)) === strlen(utf8_decode($str))) ? $out : $out.$end_char; + return (mb_strlen($out) === mb_strlen($str)) ? $out : $out.$end_char; } } } |