简体   繁体   中英

PHP GD Text and Special Characters / Encoding?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM