Introduction
In this article I describe how to use PHP to reverse a string and how to determine whether a string is empty. To learn some other string functions, go to:
- String Functions in PHP: Part1
- String Functions in PHP:Part2
- String Functions in PHP:Part3
- String Functions in PHP:Part4
- String Functions in PHP:Part5
- String Functions in PHP:Part6
- String Functions in PHP:Part7
- String Functions in PHP:Part8
- String Functions in PHP:Part9
- String Functions in PHP:Part10
Reverse string
To reverse a string you can simply use the strrev() function.
Example
The following example shows how to reverse a string using the strrev() function. The strrev() function takes a string argument like "PHP nrael I" and returns the entire string in reverse order like "I learn PHP".
<?php
// define string
$str = "PHP nrael I";
// reverse string
// result: "detpecca sserpxE naciremA dna draCretsaM ,asiV"
$revstr = strrev($str);


Join the conversation! Your thoughts help the community grow.