Skip to content

Instantly share code, notes, and snippets.

@glagola
Created September 25, 2012 07:51
Show Gist options
  • Save glagola/3780512 to your computer and use it in GitHub Desktop.
Save glagola/3780512 to your computer and use it in GitHub Desktop.
Обрезает строку по длине, не разрезая слова. Корректно работает с UTF-8.
<?php
function smartCut($str, $len, $enc = 'UTF-8') {
return (mb_strlen($str, $enc) > $len) ? mb_substr($str, 0, mb_strpos($str, ' ', $len, $enc), $enc) : $str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment