----- Original Message -----
From: "Floyd Baker" <[EMAIL PROTECTED]>
To: "Henrik Hansen" <[EMAIL PROTECTED]>
Cc: "Henrik Hansen" <[EMAIL PROTECTED]>; "PHP General List"
<[EMAIL PROTECTED]>
Sent: Tuesday, May 22, 2001 8:16 PM
Subject: Re: [PHP] Is this a typo or what?
> On 22 May 2001 19:32:00 +0200, you wrote:
>
> >Floyd Baker <[EMAIL PROTECTED]> wrote:
> >
> > >
> > > I removed one of the two above the bottom 'return rettext'.
> > >
> >
> >There are sure something with that script, at least I found out there
> >is a } too much, maybe you removed one too many, can i see the
> >original script? I would also advise you to try and ident the script
> >correctly which makes it like 100% easier to read.
> >
> >--
> >Henrik Hansen
>
>
> http://www.php.net/manual/en/ref.strings.php
>
> The top example of user contributed notes. I didn't take anything
> out.. It comes that way... with 15 brackets. <g> The extra one I
> think is the second (or third) one up from the bottom.
>
> Yes I have the whole thing indented to make sense. I am still working
> on it to make it work.
>
> Floyd
>
Floyd,
This works fine for me (if this is the correct example you were looking at):
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 . "<br>";
$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 . "<br>";
$linebuf = $after;
$linelen = strlen($after);
}else{
$linebuf = $linebuf . " " . $elem;
$linelen = $linelen + $elemlength;
}
}
return $rettext;
}
$test = wraptext("this is just a test to see if this thing works if not the
fuck it.", "10");
echo"$test";
--
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]