There are several ways you can reverse a string in PHP. One is using default function and the 2nd way is without using default function.
Here is the one using default PHP reverse function:
Syntax:
1 |
string strrev ( string $string ) |
Example:
1 2 3 4 5 6 7 |
<?php $str = "RADIO"; echo strrev ( $str ); ?> |
Without using default string functions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php //your string $string = 'TEST'; //find string length $len = strlen($string); //loop through it and print it reverse for ( $i = $len - 1; $i >=0;$i-- ) { echo $string[$i]; } ?> |
You got how it is working now?. Enjoy then.
a very easy program
nice example