top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How do I reverse a string in PHP?

0 votes
434 views
How do I reverse a string in PHP?
posted Jul 11, 2014 by Amanpreet Kaur

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

There's strrev() to do this.

if you want to built it on your own (for learning?): your problem is that you're starting with your index one too high - a string of legth 25 is indexed from 0 to 24, so your loop hast to look like this:

for ($i = $len - 1; $i >=0;$i--)
{
  echo $stringExp[$i];
}
answer Jul 12, 2014 by Vrije Mani Upadhyay
0 votes

It is extremely simple, so here it is in operation:
<?php $data = "Hello"; echo strrev($data); //olleH ?>

answer Jul 15, 2014 by Rahul Mahajan
...