Chinese Garbled text-how does PHP match whether the text contains garbled characters?

Source: Internet
Author: User
Websites often submit garbled user names. How can I use PHP to determine whether the text contains garbled characters? {Code...} websites often submit garbled user names. How can I use PHP to identify whether the text contains garbled characters?

php# UTF-8 $ str = 'accreditation '; preg_match_all ('/(...)/', $ str, $ matches); print_r ($ matches); die;
Array ([0] => Array ([0] => do [1] => [2] => Certificate) [1] => Array ([0] => Office [1] => [2] => Certificate ))

Reply content:

Websites often submit garbled user names. How can I use PHP to determine whether the text contains garbled characters?

php# UTF-8 $ str = 'accreditation '; preg_match_all ('/(...)/', $ str, $ matches); print_r ($ matches); die;
Array ([0] => Array ([0] => do [1] => [2] => Certificate) [1] => Array ([0] => Office [1] => [2] => Certificate ))

This is caused by inconsistent front-end and back-end encoding. When the front-end inputs, you should determine whether to allow users to enter invalid characters.

The following is a supplement:

php
  

The three characters are encoded\u529e\ue708\u8bc1It's UTF-8. I don't know how to do this.

First, the front-end should judge and process illegal characters when entering them, so as to avoid Garbled text. Second, the front-end and back-end codes should be consistent to avoid Garbled text.

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.