How to reverse given string without using built in functions?

Showing Answers 1 - 15 of 15 Answers

chatthan

  • Apr 4th, 2007
 

print the charcters of the string in reverse order... using a for loop.. from 0 to length of string .. and print in reverve order.. thats all

Manish Painuly`

  • Jun 28th, 2007
 

with function:

WE CAN USE strrev() function


without function

for($i=0;sizeof($str_name)>$i;$i++)
{

for($l=1;$i-$l;$l--)
{
//print string here
}

  Was this answer useful?  Yes

neeraj

  • Sep 14th, 2007
 


 $len = strlen($str_name);
for($i=($len-1); $i>=0;$i--)
  {
   echo $str_name[$i];
  }

<?php
    $st = "ARUMUGAM";
    $len = 1;
    $length = 0;
    for($i=0; $i<$len; $i++){
        if(isset($st[$i])){
            //print $st[$i];
            //print "<br/>";
            $length = $i;
        }
        if($length != $i){
            break;
        }
        if($i == ($len-1)){
            $len = $len + 1;
        }
    }
   
    //print $length;
    //print "<br/>";
    for($i=$length; $i>=0; $i--){
        print $st[$i];
    }
?>

amitdubey2

  • Mar 29th, 2010
 

<?php
$str_name='Sachin Tendulkar';
$len=strlen($str_name);
//echo $len;
$i=$len;
for ($i;$i>-1;$i--)   
//$i>-1 because in array Ist element is start with 0th position.
{
echo $str_name[$i];
}
?>

Prerna

  • Nov 11th, 2014
 

Code
  1.  $str="PRERNA"

  Was this answer useful?  Yes

rajesh

  • Jun 2nd, 2015
 

Code
  1. $string="rajesh"

  Was this answer useful?  Yes

Vishnu R menon

  • Dec 28th, 2015
 

$val="vishnu menon is a good boy";
echo(implode(array_reverse(str_split($val))));

  Was this answer useful?  Yes

Dharmendra Singh

  • Feb 3rd, 2016
 

Copy below code and run on your host

Code
  1. span style="color: #0000ff;">"display_errors", "0""""margin:30vh auto; text-align:center;""form1" method="post" action="<?php echo $_SERVER[PHP_SELF]; ?>" >

  2.     <input type="text" name="text" />

  3.     <input type="submit"

  Was this answer useful?  Yes

manish

  • Jul 25th, 2016
 

Reverse String Program

Code
  1. span style="font-style: italic;">// reverSe String Program

  2. $a="Manish kumar 123"

  Was this answer useful?  Yes

Ankit

  • May 25th, 2017
 

Reverse String Program

Code
  1.  $string = "ABCDE"

  Was this answer useful?  Yes

bibin

  • Jan 12th, 2018
 

Function reversestring($string) {
$len = strlen($string);
for($i = $len-1; $i>=0; $i--) {
echo $string[$i];
}
}
$revstr = reversestring(COMPUTER);

Code
  1.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions