Home > Backend Development > PHP Tutorial > PHP implements Chinese and English reverse order

PHP implements Chinese and English reverse order

WBOY
Release: 2016-08-08 09:28:31
Original
1032 people have browsed it

/*
* Created on 2011-11-09
* @author sundebiao
* This can achieve the reverse order of strings
* Supports pure English numbers, pure Chinese strings and mixed Chinese and English number strings
* Chinese needs to use GBK encoding
* If the incoming parameter is not a string, false will be returned
*/
function strrev_ext ($str)
{

$str = iconv('UTF-8', 'GBK', $str) ;
if (is_string($str)) {
$len = strlen($str);
$newstr = "";
for ($i = $len - 1; $i >= 0; $i -- ) {
                                                                                            
          else {
                                                                                                                                                     $newstr. }
}
//Function usage demonstration
//Pure English characters
$str ="abcde";
echo strrev_ext($str)."
";
//Pure Chinese characters
$str1 = "Chinese";
echo strrev_ext($str1)."
//Chinese and English mixed
$str2= "中文国US人1br";
echo strrev_ext($str2)."
";
The above introduces the implementation of Chinese and English reverse order in PHP, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template