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.