Encounter a PHP interview problem, the topic is very short, also very common, but more prone to error, the topic is as follows
How do I implement string flipping?
The first reaction, of course, is the Strrev function, so easy to put the topic in the interview exam, really not too much trouble ah? But after reading the answer on the Internet, I found myself wrong.
The Strrev function is good for English and can be used to flip strings, but in the face of Chinese? Must be garbled, for such a problem there are many, such as STRSTR,SUBSTR and other functions are like this. Fortunately, PHP provides the functions of the Mb_ class to implement different encodings, inter-language conversion and other operations. Here is the PHP string flip function I wrote (the function of the Mb_ class needs to open a mb_string implementation).
= 0; $i-) {$result. = Mb_substr ($str, $i, 1, $encoding);} return $result; } $string = ' OK you are right ole '; echo Getrev ($string);?>
Output Result:
----------PHP Debugger----------Elo really exactly what you KO Output completed (0 sec consumed)-Normal termination