Home  >  Article  >  Backend Development  >  What should I do if the Chinese watermark in the PHP gd library is garbled?

What should I do if the Chinese watermark in the PHP gd library is garbled?

藏色散人
藏色散人Original
2021-03-29 09:38:211626browse

php gd library adds Chinese watermark garbled solution: 1. Remove the "--enable-gd-jis-conv" option and recompile php; 2. Convert the characters into html entities.

What should I do if the Chinese watermark in the PHP gd library is garbled?

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php uses the Gd library to add garbled text watermarks Problems and solutions

Recently a project underwent server migration. After deployment, it was discovered that one of the functions of adding watermark text to pictures had garbled problems. Confirm that there is no problem with the function code, and at the same time the project code They all use UTF-8 encoding, and there is no encoding problem. We also checked and ruled out the possibility of problems with the font files. After consulting the information, we finally found a PHP compilation parameter --enable-gd-jis-conv.

--enable-gd-jis-conv:

If the --enable-gd-jis-conv option is enabled when PHP is compiled, then non-ASCII characters (such as Chinese characters, Pinyin, Greek text and arrows) will be regarded as EUC-JP encoding, eventually causing normal Chinese to become garbled

Solution:

1. Remove the --enable-gd-jis-conv option and re- Compile php

2. Convert characters to html entities

mb_convert_encoding ('Test', 'HTML-ENTITIES', 'UTF-8');

[Recommended learning :PHP video tutorial

The above is the detailed content of What should I do if the Chinese watermark in the PHP gd library is garbled?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn