PHP Function long_line

This function should split a long line at a specified width. Preserving words, only splitting at spaces.

function long_line($line,$chars,$debug=0) { if ($debug) { print "processing: $line<br />\n"; } $ret = substr($line,0,$chars); $count = $chars; while ($char != " ") { $char = substr($line,$count,1); if ($char == '') { return $ret; } if ($debug) { print "$count: '$char'<br />\n"; } $ret .= $char; $count++; } $ret .= "<br />\n"; $mystr = substr($line,$count); $ret .= long_line($mystr,$chars,$debug); return $ret; }


Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 3.140.197.140
To prevent spam please submit by clicking the kitten: