diff options
author | Andrew Dolgov <[email protected]> | 2018-12-24 12:44:10 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2018-12-24 12:44:10 +0300 |
commit | 1351ce370ac60d3f02329b49b3ccbe33d353c2f4 (patch) | |
tree | 1cac3a8a8d96e00290e388c1a9811b26f9d193bc /include | |
parent | 215c9f0f885f6c761349c363e16a9f9c2d7abde4 (diff) |
truncate_middle: make it utf8 aware
Diffstat (limited to 'include')
-rwxr-xr-x | include/functions.php | 14 |
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 = '…') { - 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; } |