PHP 7.1.21 Released

strrev

(PHP 4, PHP 5, PHP 7)

strrevReverte uma string

Descrição

string strrev ( string $string )

Retorna a string revertida.

Parâmetros

string

A string a ser revertida.

Valor Retornado

Retorna a string revertida.

Exemplos

Exemplo #1 Revertendo uma string strrev()

<?php
echo strrev("Hello world!"); // mostra "!dlrow olleH"
?>

add a note add a note

User Contributed Notes 3 notes

up
1
tianyiw at vip dot qq dot com
1 month 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
-1
arturklesun at gmail dot com
5 months ago
Be careful, it does not work with unicode strings.

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

php
> print(strrev($str));
��1
?>
up
-24
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