Working with GD ( imagettftext() ) and UTF-8 characters

余生长醉 提交于 2019-11-27 16:03:53

As I continued my research I came up with an answer for my problem, this piece of code did it!

private function properText($text){
    $text = mb_convert_encoding($text, "HTML-ENTITIES", "UTF-8");
    $text = preg_replace('~^(&([a-zA-Z0-9]);)~',htmlentities('${1}'),$text);
    return($text); 
}

Now all the characters (and all the new ones I've seen) that troubled me are displayed correctly!

In first place make sure your IDE is not saving file in another encoding than UTF8. For example new Intellij IDEA 9 changed UTF-8 to WINDOWS-1250 on Windows platform. If you won't notice that and you will use constant strings for testing, it is pretty crazy to debug.

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