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
Replies
July 14th 2003 -
You've just been bitch slapped!
July 23rd 2005 - Wiziwig
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?