In Sunday, the site https://www.javasec.cn bug fixes and feature updates, which encountered a relatively interesting little problem:
Questions:
Web site's top recommendation, there is text slightly reduced. However, no matter how to modify the last character is always garbled.
Because the front end uses template parsing, {content} ... So I can't see what's causing the problem, follow up and find out where it is.
Solve:
1. Check whether this Chinese is not utf-8, is not this text garbled
2. Check that the PHP configuration database is encoded correctly
3. check that the database encoding is correct
4. View the build source for {contnet}
Echo Str_replace (array(' {permalink} ', ' {title} ', ' {content} '),array($val$val[' title '],substr ($val[' Text '],0,250, ' utf-8 '),$defaults[' Xformat ']);
Find this conent data source, because substr () according to bytes, Chinese bytes are more special, so there is no way to ensure that the interception of the correct circumstances, decisively abandoned the function.
Echo Str_replace (array(' {permalink} ', ' {title} ', ' {content} '),array($val$val[' title '],mb_ substr ($val[' Text '],0,130, ' utf-8 ')),$defaults[' Xformat ']);
Solve.
PHP use substr Chinese garbled problem