The regular expression inside the while loop is shorter and uses preg_match() instead of preg_replace(). That should improve performance and prevent a strange bug (Compilation failed: regular expression too large)

Hi,
shouldn’t be mb_substr and mb_strlen at line 29? But it is not working for me even with mb_ functions. Mixing \r\n and \n (passed \r\n as $break), breaking after 13 characters on 18-chars line with 75 passed as $width, cutting words in the middle (short words - less chars then $width)…
Sorry, but this function is unusable, searching furthermore…

Excellent work. Thanks for the improvements. Now, my problem is that URLs got cut as well. It would be nice to have a full text treatment function that could take text mixed with URLs, wrap the URLs with link tags, and then word-cut the text (including the link’s inner text [the url])