note 2263 deleted from ref.strings by sander

From: Date: Sun, 07 Apr 2002 13:35:17 +0000
Subject: note 2263 deleted from ref.strings by sander
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-28911@lists.php.net to get a copy of this message
A quick and dirty function to wrap text at a given wrap margin: <p> function wraptext($text, $wrapmargin) { $rettext = ""; $linebuf = ""; $linelen = 0; $tok = split("[ \t]", $text); $numtok = count($tok); for ($i = 0; $i < $numtok; $i++) { $elem = $tok[$i]; $elemlength = strlen($elem) + 1; if ($linelen + $elemlength > $wrapmargin) { $rettext = $rettext . $linebuf . "\n"; $linebuf = ""; $linelen = 0; } // Do we have a newline in this element? $pos = strrpos($elem, "\n"); if ($pos) { $before = substr($elem, 0, $pos); $after = substr($elem, $pos); $rettext = $rettext . $linebuf . " " . $before . "\n"; $linebuf = $after; $linelen = strlen($after); } else { $linebuf = $linebuf . " " . $elem; $linelen = $linelen + $elemlength; } } return $rettext; }

« previous php.notes (#28911) next »