PHP version of the micro-trust public platform to reply to the Chinese garbled problem solving method _php Skills

Source: Internet
Author: User

In this paper, we analyze the solution to the problem of garbled text in the PHP version of micro-trust public platform. Share to everyone for your reference, specific as follows:

Micro-trust in the development of the public when the reply to Chinese garbled, the problem is a small set of coding problems, in fact, as long as the code into a UTF8 can be solved, specifically to see.

Many micro-trust public platform of the automatic recovery program is ThinkWechat.class.php this kind of development, today encountered a baffling garbled problem, check the problem found is GB2312 coding, so to modify the source code.

Add a method first:

/**
 * Detect if UTF-8
 * @param $str
 * @return bool
/Private Function Is_utf8 ($str)
{
  return Preg_match ('//u ', $str);
}
Find
$this->data [' Content '] = $content;
Modify to
if ($this->is_utf8 ($content)) {
  $this->data [' content '] = $content;
} else {
  $this- >data [' Content '] = iconv (' gb2312 ', ' Utf-8//ignore ', $content);
}
Can

For more information on PHP related content readers can view the site topics: "PHP micro-credit Development Skills summary", "PHP coding and transcoding Operation skills Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP string (String) Usage Summary", "php+ MySQL Database operations Introduction tutorial and PHP Common database operation Skills Summary

I hope this article will help you with the PHP program design.

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.