After searching and being tired of many non-working mb_wordwrap functions at many places, I finally created a really simple and working solution
<?php
function mb_wordwrap($string, $limit)
{
$string = strip_tags($string); $string = html_entity_decode($string); $string = str_replace(array("\r", "\n"), "", $string); if(mb_strlen($string, "UTF-8") <= $limit) return $string; $last_space = mb_strrpos(mb_substr($string, 0, $limit, "UTF-8"), " ", 0, "UTF-8"); return mb_substr($string, 0, $last_space, "UTF-8").' ...'; }
?>
The function simply searches the last space symbol in the range and returns the string cut till that position. No iterations, no regular expressions and no buffer overload. Tested with large Russian texts and works perfectly.