Hehe, managed to do it on first try. This should do it :
<?php
$string = "hello world";
$length = strlen($string);
if($length>1){
$reversed = "";
for($i=0;$i<$length;$i++){
$reversed .= substr($string,$length-$i,1);
echo substr($string,$length-$i,1) . "<br>";
}
$reversed .= substr($string,0,1);
echo substr($string,0,1) . "<br>";
echo $reversed;
} else echo $string;
?>
I added some errochecking if the string is only 1 character, since there
should be no use in running the for loop then.
--
--
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
----------------------------------------------------------------------
"Kristian Rasmussen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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;
> ---
>
> With, obviously, no success. Is this the way or could array_reverse()
> somehow be used?
>
> Kristian
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php