search for in the  
<strrchrstrripos>
Last updated: Thu, 19 May 2005

strrev

(PHP 3, PHP 4, PHP 5)

strrev -- Reverse a string

Description

string strrev ( string string )

Returns string, reversed.

Example 1. Reversing a string with strrev()

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



User Contributed Notes
strrev
MagicalTux at FF dot st
12-May-2005 08:20
I will make Screend at hf dot webex dot com's comment more clear and understandable.

strrev only works for singlebyte character-sets. Multibytes charactersets are not compatibles with strrev.

US-ASCII and ISO-8859-1 are compatible with strrev, however BIG5, SJIS, UTF-8 aren't.

Despite what you can think, ISO-8859-15 *is* multibyte (the euro symbol - € - is coded on two bytes).

There's no mb_strrev function in PHP, so you can't strrev() a multibyte string. Try to convert it to something else with iconv() if it can be represented in a singlebyte character set.
avarab at gmail dot com
07-May-2005 02:53
strrev() can be very useful in cases where it makes more sense to do something from the end of a string rather than the beginning (well duh!) such as apply certain regular expressions. Here's a small function to add commas to numbers that works in such a way.

<?php
echo commafy("1500000.1254"); // prints 1,500,000.1254

function commafy($_) {
       return
strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,' , strrev( $_ ) ) );
}
?>

I originally wrote it in Perl, does it show? ;=)
Screend at hf dot webex dot com
30-Mar-2004 10:17
this function can only reverse the 1-byte words,like english,it seems,using
<?php
$str
=strrev("ºº×Ö");
echo
$str;
?>
do not get a right result.
but,you can change 2-bytes characters into a ASCLL,the converse it.

<strrchrstrripos>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT