1、
When using Yii2's Model to fetch data, some data will have Malformed UTF-8 characters errors. After checking for a long time, there is no answer.
After data comparison and analysis, when the type of a field in the database is varbinary and the value is not empty, an error occurs when using json_encode. I use varbinary to store the IP, and I have not paid attention to this problem.
So, before json_encode, use
$data['last_ip'] = inet_ntop($data['last_ip']);
After the data is converted and output, the problem is solved. I hope it will be helpful to everyone. At the same time, I also remember to prevent such problems from wasting time in the future.
Collected from Zifeiwu 's blog post: https://blog.csdn.net/qq940390/article/details/107245619/
2. Malformed UTF-8 characters error will also occur when using the substr function to process strings with spaces
The solution is to use str_replace to remove the spaces, and then use the substr function