PHP use substr Chinese garbled problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.