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; }
Leave A Reply - 2 Replies
Anonymous 2003-07-14 04:36pm - No Email - Logged IP: unknown

You've just been bitch slapped!
Wiziwig 2005-07-23 09:17pm - - Logged IP:

How would I break apart long characters with a line break? for instance let's say I wanted to preserve a cell width and let's say my displayed input line in that cell is sure to broaden that width if anyone puts in a continous line. something like: wuwuwywtejkhuhdwuguweugyie2lhuofndeuouohdfuoeh8hhfeufh8hfgh2f8fheu9u. There;s no breaks in that line to find as you can see. So how would I force a line break after so many predefined characters?

All content licensed under the Creative Commons License