Guest User

Untitled

a guest
Oct 16th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. function cut_string($Str, $Length, $Hard = false, $ShowDots = true) {
  2.     if (mb_strlen($Str, 'UTF-8') > $Length) {
  3.         if ($Hard == 0) {
  4.             // Not hard, cut at closest word
  5.             $CutDesc = mb_substr($Str, 0, $Length, 'UTF-8');
  6.             $DescArr = explode(' ', $CutDesc);
  7.             if (count($DescArr) > 1) {
  8.                 array_pop($DescArr);
  9.                 $CutDesc = implode(' ', $DescArr);
  10.             }
  11.             if ($ShowDots) { $CutDesc .= '...'; }
  12.         } else {
  13.             $CutDesc = mb_substr($Str, 0, $Length, 'UTF-8');
  14.             if ($ShowDots) { $CutDesc .= '...'; }
  15.         }
  16.         return $CutDesc;
  17.     } else {
  18.         return $Str;
  19.     }
  20. }
Add Comment
Please, Sign In to add comment