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. |
`------------------------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php