I encountered two small php problems in the company. I wrote them down so that I can see how they can be solved in the future.
sleep(10); If it is not placed in the for loop, the execution will continue below the process without waiting. .
mb_strlen(val,"utf-8");
It’s still a question about Chinese. PHP's built-in string length function strlen cannot handle Chinese strings correctly. All it gets is the number of
bytes occupied by the string. For the Chinese encoding of GB2312, the value obtained by strlen is 2 times the number of Chinese characters, while for UTF-8 encoded Chinese, the difference is 3 times
(under UTF-8 encoding, one Chinese character occupies 3 characters Festival).
Using the mb_strlen function can better solve this problem. The usage of mb_strlen is similar to strlen, except that it has a second optional parameter for
to specify the character encoding. For example, to get the UTF-8 string $str length, you can use mb_strlen($str,UTF-8). If the second parameter is omitted,
will use PHP's internal encoding. The internal encoding can be obtained through the mb_internal_encoding() function. It should be noted that mb_strlen is not a
PHP core function. Before using it, you need to make sure that php_mbstring.dll is loaded in php.ini, that is, make sure that the line "extension=php_mbstring.dll"
exists and is not commented out. , otherwise the problem of undefined function will occur.