To phpkid:
This is a much simpler solution.
<?php
function longWordWrap($string) {
$string = str_replace("\n", "\n ", $string); // add a space after newline characters, so that 2 words only seperated by \n are not considered as 1 word
$words = explode(" ", $string); // now split by space
foreach ($words as $word) {
$outstring .= chunk_split($word, 12, " ") . " ";
}
return $outstring;
}
?>