summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-12-24 12:44:10 +0300
committerAndrew Dolgov <[email protected]>2018-12-24 12:44:10 +0300
commit1351ce370ac60d3f02329b49b3ccbe33d353c2f4 (patch)
tree1cac3a8a8d96e00290e388c1a9811b26f9d193bc /include
parent215c9f0f885f6c761349c363e16a9f9c2d7abde4 (diff)
truncate_middle: make it utf8 aware
Diffstat (limited to 'include')
-rwxr-xr-xinclude/functions.php14
1 files changed, 11 insertions, 3 deletions
diff --git a/include/functions.php b/include/functions.php
index 24c251bd3..97dbbff15 100755
--- a/include/functions.php
+++ b/include/functions.php
@@ -863,10 +863,18 @@
}
}
- // is not utf8 clean
+ function mb_substr_replace($original, $replacement, $position, $length) {
+ $startString = mb_substr($original, 0, $position, "UTF-8");
+ $endString = mb_substr($original, $position + $length, mb_strlen($original), "UTF-8");
+
+ $out = $startString . $replacement . $endString;
+
+ return $out;
+ }
+
function truncate_middle($str, $max_len, $suffix = '&hellip;') {
- if (strlen($str) > $max_len) {
- return substr_replace($str, $suffix, $max_len / 2, mb_strlen($str) - $max_len);
+ if (mb_strlen($str) > $max_len) {
+ return mb_substr_replace($str, $suffix, $max_len / 2, mb_strlen($str) - $max_len);
} else {
return $str;
}