PHP interview questions ?? PHP string flip function encounters a PHP interview question. The question is short and common, but it is more prone to errors. The question is as follows:
How to implement string flip?
First, of course, it's the strrev function. isn't it really troublesome to put such an easy question into the interview? However, after reading the online answers, I found myself wrong ~~~
The strrev function is easy to use in English and can be used to flip strings directly, but what about Chinese? It must be garbled. There are many such problems, such as strstr and substr. Fortunately, PHP provides functions of the mb _ class for mutual conversion between different encodings and languages. Below is the PHP string flip function I wrote (mb _ class function needs to enable an mb_string implementation ).
= 0; $ I --) {$ result. = mb_substr ($ str, $ I, 1, $ encoding);} return $ result;} $ string = 'OK, you are the correct olean '; echo getRev ($ string);?>
Output result:
---------- PHP Debugger ---------- elO is indeed your KO Output completed (0 sec consumed)-Normal Termination