Yes, I thought of wordwrap, but it wouldn't serve my purpose.
The reason is that wordwrap has no knowledge of word boundaries. Rather it wraps based on number of characters per line.
Let's say I have this:
$text = '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! today is sunday';
and I decide on 40 xters,
wordwrap($text, 40, "<br />\n");
the result would be:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! tod
ay is sunday
Anyway I wrote a javascript solution that does on-the-fly editing as the user types.