Advertisement
AMONRA75

PHP - FUNCTION SHORT

Feb 11th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.32 KB | None | 0 0
  1. function short_str($str, $max = 20) {
  2.     $str = trim($str);
  3.     if (strlen($str) > $max) {
  4.         $s_pos = strpos($str, ' ');
  5.         $cut = $s_pos === false || $s_pos > $max;
  6.         $str = wordwrap($str, $max, ';;', $cut);
  7.         $str = explode(';;', $str);
  8.         $str = $str[0] . '...';
  9.     }
  10.     return $str;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement