Home >Backend Development >PHP Tutorial >Solution to garbled Chinese characters in phpword_PHP tutorial
This article introduces the solution to garbled Chinese characters in phpword. I hope this article will be helpful to everyone.
Recently, the leader requested to use PHP to generate word, and I found many classes and functions on the Internet. Finally I fell in love with phpword. Unfortunately, it was not developed by Chinese people, and it is very unfriendly to Chinese support. After research, I finally solved the Chinese garbled code and shared it.
1. Use template word to generate Chinese garbled word solution:
Open the phpword/Template.php file, find $replace = utf8_encode($replace); change it to $replace =iconv('gbk', 'utf-8', $replace); and that's it.
2. Directly generate word documents and solve Chinese garbled characters when calling the addText object:
Open the phpword/Section.php file, find $givenText = utf8_encode($text); change it to $givenText = iconv('gbk', 'utf-8', $text);.
3. It seems that other methods have similar solutions.
4. Note that the php file uses gbk. Anyway, my display is in Chinese. I searched online for a long time and researched for a long time before I finally figured it out.