Header ("Content-type:text/html;charset=utf-8"); /** The function is to reverse the Chinese string Mb_strlen () Gets the length of the character Mb_substr () gets a single element of the character Krsort () sorts an array in reverse order of key values Implode () stitching an array into a string Explode () separating strings with strings */ function Str_rev_gb ($STR) { Determine if the input is not a UTF8 type character, otherwise exit if (!is_string ($STR) | |! Mb_check_encoding ($str, ' UTF-8 ')) { Exit ("The input type is not a string of type UTF8"); } $array =array (); Depositing strings into an array $l =mb_strlen ($str, ' UTF-8 '); for ($i =0; $i < $l; $i + +) { $array []=mb_substr ($str, $i, 1, ' UTF-8 '); } Invert string Krsort ($array); Stitching strings $string =implode ($array); return $string; } $str 1 = "englist"; $str 2 = "中文版 China"; $str 3 = "Eng lish country"; $str 4 = "People's Republic of China"; echo $str 1. " ". STR_REV_GB ($str 1)." "; echo $str 2. " ". STR_REV_GB ($str 2)." "; echo $str 3. " ". STR_REV_GB ($str 3)." "; Echo $str 4. " ". STR_REV_GB ($str 4)." "; |