In fact, you can use the wordwrap() filed in explode() using the newline character \n as a delimiter. explode() will split the line into newline created by wordwrap() .
$strText = "The quick brown fox jumps over the lazy dog"; // Wrap lines limited to 12 characters and break // them into an array $lines = explode("\n", wordwrap($strText, 12, "\n")); var_dump($lines); array(4) { [0]=> string(9) "The quick" [1]=> string(9) "brown fox" [2]=> string(10) "jumps over" [3]=> string(12) "the lazy dog" }
source share