问题
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