PHP GD文本和特殊字符/编码? [英] PHP GD Text and Special Characters / Encoding?
问题描述
我正在使用imagettftext在php中生成文本.文本是从mysql数据库中提取的.尽管某些字符已出现在字体的字符图中并出现在数据库中,但它们仍未出现在渲染的文本中.例如m-破折号(—)和智能引号/撇号("’).
I'm generating text in php using imagettftext. the text is being pulled from a mysql database. some characters are not appearing in the rendered text despite being in the character map for the font and appearing in the database. for example, m-dashes (—)and smartquotes/apostrophes (""’).
字符不出现或被问号代替.
the characters either don't appear or are replaced by question marks.
我怀疑这与编码有关,但是我对编码了解不足,无法知道从哪里开始.任何帮助将不胜感激.
i suspect this has to do with encoding, but i don't know enough about encoding to know where to start. any help would be much appreciated.
推荐答案
在将文本传递给函数之前,尝试对文本使用 htmlentityencode
.
Try using htmlentityencode
on the text before you pass it to the function.
采用UTF-8编码的文本字符串.
The text string in UTF-8 encoding.
可以包含十进制数字字符引用(格式为:€
),以访问位置127之后的字体中的字符.十六进制格式(如©
).可以直接传递UTF-8编码的字符串.
May include decimal numeric character references (of the form: €
) to access characters in a font beyond position 127. The hexadecimal format (like ©
) is supported. Strings in UTF-8 encoding can be passed directly.
命名实体,例如&
.考虑使用html_entity_decode()将这些命名实体解码为UTF-8字符串(从PHP 5.0.0开始,html_entity_decode()支持此功能).
Named entities, such as ©
, are not supported. Consider using html_entity_decode() to decode these named entities into UTF-8 strings (html_entity_decode() supports this as of PHP 5.0.0).
如果在字体不支持的字符串中使用了字符,则空心矩形将替换该字符.
If a character is used in the string which is not supported by the font, a hollow rectangle will replace the character.
来源: http://www.php.net/manual/zh-CN/function.imagettftext.php
这篇关于PHP GD文本和特殊字符/编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!