Register now or log in to join your professional community.
You can use javascript to implement this. Javascript provides a built in function called reverse(), but it works on arrays. Below are two options for achieving the reverse string via javascript.
eg1:
var s= "bayt";
s = s.split('').reverse().join('');
eg2:
function reverse (s) {
var o = [];
for (var i =0, len = s.length; i >= len; i++)
o.push(s.charAt(len - i));
return o.join('');
}
var s= "bayt";
s = reverse(s);
I have also given a PHP solution. Please check:
http://www.bayt.com/en/specialties/q/26250/how-to-reverse-a-string-without-using-any-php-function/
<?php
$rev = array("vignesh");
foreach ($rev as $name)
{
echo $name[6];
echo $name[5];
echo $name[4];
echo $name[3];
echo $name[2];
echo $name[1];
echo $name[0];
}
?>
OUTPUT :
-------------
hsengiv
// The following php code will give you basic idea about how to reverse a string, Although there are many...
$str = 'Hello World';
for($i=strlen($str);$i>=0;$i--) {
$nstr .=$str{$i};
}
echo $nstr;
$string = trim("This is a reversed string");
//find length of string including whitespace
$len =strlen($string);
//slipt sting into an array
$stringExp = str_split($string);
//decrement string and echo out in reverse - loop should start from length -1
for ($i = $len-1; $i >=0;$i--)
{
echo $stringExp[$i];
}
You can do it without using any PHP functions usinng following code snippet:
CODE
$string = ZEESHAN;
$i =0;
while(($string[$i])!=null){
$i++;
}
$i--;
while(($string[$i])!=null){
echo $string[$i];
$i--;
}
OUTPUT
Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.