parent root
PHP: strrev - Manual

strrev

(PHP 4, PHP 5, PHP 7)

strrevReverse a string

Description

strrev ( string $string ) : string

Returns string, reversed.

Parameters

string

The string to be reversed.

Return Values

Returns the reversed string.

Examples

Example #1 Reversing a string with strrev()

<?php
echo strrev("Hello world!"); // outputs "!dlrow olleH"
?>
add a noteadd a note

User Contributed Notes 2 notes

up
5
tianyiw at vip dot qq dot com
1 year ago
This function support utf-8 encoding, Human Language and Character Encoding Support:

<?php
function mb_strrev($str){
   
$r = '';
    for (
$i = mb_strlen($str); $i>=0; $i--) {
       
$r .= mb_substr($str, $i, 1);
    }
    return
$r;
}

echo
mb_strrev("☆❤world"); // echo "dlrow❤☆"
?>
up
-6
arturklesun at gmail dot com
1 year ago
Be careful, it does not work with unicode strings.

<?php
php
> $str = '1Â¥';
php > print($str);
1Â¥
php
> print(strrev($str));
��1
?>
To Top
parent root