Mid-Atlantic Developer Conference

strrev

(PHP 4, PHP 5, PHP 7)

strrevReverse a string

Description

string strrev ( 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 note add a note

User Contributed Notes 2 notes

up
1
arturklesun at gmail dot com
1 month ago
Be careful, it does not work with unicode strings.

<?php
php
> $str = '1¥';
php > print($str);

php
> print(strrev($str));
��1
?>
up
-16
carmel.alex at gmail.com
12 years ago
This function support utf-8 encoding

function utf8_strrev($str){
    preg_match_all('/./us', $str, $ar);
    return join('',array_reverse($ar[0]));
}
To Top