in php potresti provare la funzione word_wrap()

http://it2.php.net/manual/it/function.wordwrap.php