Solution to WeChat public platform php garbled code: first open the corresponding source code file; then add the content as "private function is_utf8($str){return preg_match('//u', $str);}.. .” That’s it.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
php version WeChat public platform replies with garbled Chinese characters Solution
This article analyzes the solution to the problem of garbled characters in Chinese replies on the PHP version of WeChat public platform. Share it with everyone for your reference. The details are as follows:
When developing the WeChat public platform, I encountered garbled Chinese characters in the replies. The editor found that this problem was an encoding problem. In fact, it can be solved by converting the encoding to utf8. Specifically Let’s take a look.
Many automatic reply programs on WeChat public platforms are developed by the ThinkWechat.class.php class. Today I encountered an inexplicable garbled code problem. After checking the problem, I found that it was caused by GB2312 encoding, so I need to modify it. Source code.
First add a method:
/** * 检测是否UTF-8 * @param $str * @return bool */ private function is_utf8($str) { return preg_match('//u', $str); } //找到 $this->data ['Content'] = $content; //修改为 if ($this->is_utf8($content)) { $this->data ['Content'] = $content; } else { $this->data ['Content'] = iconv('gb2312', 'UTF-8//IGNORE', $content); } //即可
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to solve the php garbled problem of WeChat public platform. For more information, please follow other related articles on the PHP Chinese website!