Re: Reversing a string?
| From: | Kim Steinhaug | Date: | Fri, 14 May 2004 14:19:09 +0000 |
| Subject: | Re: Reversing a string? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-186232@lists.php.net to get a copy of this message | ||
hehe,
Reading the manual is somewhat not so bad after all...
--
--
Kim Steinhaug
----------------------------------------------------------------------
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
----------------------------------------------------------------------
www.steinhaug.com - www.easywebshop.no - www.webkitpro.com
----------------------------------------------------------------------
"Robert Cummings" <robert@interjinn.com> wrote in message
news:1084484100.5544.25.camel@blobule.suds...
> On Thu, 2004-05-13 at 17:27, Kristian Rasmussen wrote:
> > Hi all,
> >
> > I need a script for reversing a string ("hello world" becomes "dlrow
> > olleh"). I have tried the following:
> >
> > ---
> > $length = strlen($i);
> > $g = "";
> >
> > while ($length > 0)
> > {
> > $g = $i[$length] . $g;
> > $length--;
> > }
> > echo $g;
>
> The following will work:
>
> $length = strlen( $i );
> $g = "";
>
> while( $length > 0 )
> {
> $g .= $i{--$length};
> }
> echo $g;
>
> But in all honesty the following is superior:
>
> $g = strrev( $i );
> echo $g;
>
> Cheers,
> Rob.
> --
> .------------------------------------------------------------.
> | InterJinn Application Framework - http://www.interjinn.com |
> :------------------------------------------------------------:
> | An application and templating framework for PHP. Boasting |
> | a powerful, scalable system for accessing system services |
> | such as forms, properties, sessions, and caches. InterJinn |
> | also provides an extremely flexible architecture for |
> | creating re-usable components quickly and easily. |
> `------------------------------------------------------------'