Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cut_string($Str, $Length, $Hard = false, $ShowDots = true) {
- if (mb_strlen($Str, 'UTF-8') > $Length) {
- if ($Hard == 0) {
- // Not hard, cut at closest word
- $CutDesc = mb_substr($Str, 0, $Length, 'UTF-8');
- $DescArr = explode(' ', $CutDesc);
- if (count($DescArr) > 1) {
- array_pop($DescArr);
- $CutDesc = implode(' ', $DescArr);
- }
- if ($ShowDots) { $CutDesc .= '...'; }
- } else {
- $CutDesc = mb_substr($Str, 0, $Length, 'UTF-8');
- if ($ShowDots) { $CutDesc .= '...'; }
- }
- return $CutDesc;
- } else {
- return $Str;
- }
- }
Add Comment
Please, Sign In to add comment