On 21 May 2001 23:22:17 +0200, you wrote:
>Floyd Baker <[EMAIL PROTECTED]> wrote:
>
> > There's an extra '}' in the first example for a word wrap function,
> > under string functions in the manual..
> >
> > I think I removed the right one but I'm still having trouble with it.
> > Can someone else take a crack at it too?
> >
>
>I dont see any extra } what i see is:
>
>$text = "The quick brown fox jumped over the lazy dog.";
>$newtext = wordwrap( $text, 20 );
>
>echo "$newtext\n";
>
>a note for wordwrap is if you use if for wrapping in html you might
>want to do something like this, to split every line with a <br>:
>
>wordwrap($text, 20, "<br>");
>
>--
>Henrik Hansen
Henrik
You are looking in the wrong area.. I'm working with php3.
> There's an extra '}' in the first example for a word wrap function,
> under string functions in the manual..
Here is what I see... and if you count the brackets, there are 15.. ?
[EMAIL PROTECTED]
12-Nov-1999 05:15
A quick and dirty function to wrap text at a given wrap margin:
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;
}
}
// 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;
}
--
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]