PHP GD Text and Special Characters / Encoding?

戏子无情 提交于 2019-12-12 03:04:41

问题


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.


回答1:


Try using htmlentityencode on the text before you pass it to the function.

The text string in UTF-8 encoding.

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.

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.

Source: http://www.php.net/manual/en/function.imagettftext.php



来源:https://stackoverflow.com/questions/11054160/php-gd-text-and-special-characters-encoding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!