I had some issues trying to get both word wrapping and new line detection but with some of the help from the comments below i got this. (thanks to jwe for the main part of the code here)
<?php
function ttfWordWrappedText($text, $strlen = 38) {
$text = urldecode($text);
$text = explode("\n", $text);
$i = 0;
foreach($text as $text)
{
while(strlen($text) > $strlen) {
$startPoint = $strlen - 1;
while(substr($text, $startPoint, 1) != " ") {
$startPoint--;
}
$line[$i][] = trim(substr($text, 0, $startPoint));
$text = substr($text, $startPoint);
}
$line[$i][] = trim($text);
$i++;
}
return $line;
}
?>
This returns an array for each newline entered and subarray for each wordwrapped line to print.
ie.
Array
(
[0] => Array
(
[0] => This is the first long line
[1] => that i entered.
)
[1] => Array
(
[0] => And this is the new line after that.
)
)