Re: Is this a typo or what?
| From: | Floyd Baker | Date: | Mon, 21 May 2001 21:58:05 +0000 |
| Subject: | Re: Is this a typo or what? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-53783@lists.php.net to get a copy of this message | ||
On 21 May 2001 23:22:17 +0200, you wrote:
>Floyd Baker <fbaker@olm1.com> 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.. ?
ptomblin@xcski.com
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;
}
--