summaryrefslogtreecommitdiffstats
path: root/system/helpers
diff options
context:
space:
mode:
authorMohammad Javad Naderi <mjnaderi@gmail.com>2013-08-22 10:53:15 +0200
committerMohammad Javad Naderi <mjnaderi@gmail.com>2013-08-22 10:53:15 +0200
commitb312d2f18e24ad980e647884e1bae6c26ceb82d8 (patch)
tree70e649ea3708ac306afcd94283494e90be0de198 /system/helpers
parenta1553a9a49b8d355de7892204759651aa3532dad (diff)
character_limiter now works correct for UTF-8 strings
strlen() doesn't return the actual length for unicode strings. For example strlen('سلام') returns 8, but length of سلام is 4. strlen(utf8_decode('سلام')) returns correct value 4. Reference: http://www.php.net/manual/de/function.strlen.php#45407
Diffstat (limited to 'system/helpers')
-rw-r--r--system/helpers/text_helper.php10
1 files changed, 5 insertions, 5 deletions
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index b2351db95..4ddf648cb 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 = '&#8230;')
{
- if (strlen($str) < $n)
+ if (strlen(utf8_decode($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($str) <= $n)
+ if (strlen(utf8_decode($str)) <= $n)
{
return $str;
}
@@ -103,10 +103,10 @@ if ( ! function_exists('character_limiter'))
{
$out .= $val.' ';
- if (strlen($out) >= $n)
+ if (strlen(utf8_decode($out)) >= $n)
{
$out = trim($out);
- return (strlen($out) === strlen($str)) ? $out : $out.$end_char;
+ return (strlen(utf8_decode($out)) === strlen(utf8_decode($str))) ? $out : $out.$end_char;
}
}
}
@@ -537,4 +537,4 @@ if ( ! function_exists('ellipsize'))
}
/* End of file text_helper.php */
-/* Location: ./system/helpers/text_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/text_helper.php */