Recently, there needs to be mbstring function related to Chinese processed as follows:
- mb_strpos
- mb_strlen
Encountered relatively little strange question, and there is no problem in running the local environment
But we have a production environment is two servers, one of which is correct, another one of returned value is incorrect
Chinese performed according to the performance of a 3-byte calculation, it is intended to be a
Internet looking for a long time that need to be converted, as the following article: https://www.awaimai.com/2605.html but in reality not the slightest effect
Finally on google to find information, the investigation found that the server, a server for the PHP5.4, one for PHP5.6
Then switch to the local 5.4 found the same problem.
PHP documentation, the default character set from the beginning to 5.4 UTF-8, but actually used in the discovery, when the correlation function for Mbstring character set: ISO-8859-1
Lenovo may be the resulting, final solution is as follows:
1. Modify the php.ini mbstring.internal_encoding parameter is UTF-8, and restart the service
2. When coding using mb_internal_encoding ( "UTF-8"); Character Set
The above two methods Jieke
Reference material
https://www.php.net/manual/zh/mbstring.configuration.php#ini.mbstring.internal-encoding
https://betakuang.me/php-the-right-way/
Author: An old <[email protected]> way to solve the problem is to solve it once