Advertisement
phpaddict

Substract text and don't breaks words

Jul 17th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.26 KB | None | 0 0
  1. // works with multibyte strings
  2. // doesn't uses regexes
  3. function substr_text($string, $length)
  4. {
  5.     if (mb_strlen($string, 'UTF-8') <= $length)
  6.     {
  7.         return $string;
  8.     }
  9.     else {
  10.         return mb_substr($string, 0, strrpos(mb_substr($string, 0, $length), ' '));
  11.     }
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement