Home >Backend Development >PHP Tutorial >PHP implements Chinese and English reverse order
/*
* 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.