How to handle with foreign languages?

喜夏-厌秋 提交于 2019-12-13 15:10:35

问题


I'm developing a brazilian website which has to support foreign characters like á, à, ó, í ú, ê, etc. It also uses AJAX so I thought better to use charset UTF-8 'cause I always get the � character and I don't know how to fix this.

My navigation menu appears correctly when using UTF-8 (since it's querying the database to render the whole menu), but I don't know how it does. Here are some screenshots of the database and how it renders:

So far so good. The trouble is that I started using Zend_Navigation for rendering breadcrumbs and I don't know what to do to get over with the � character i'm getting:

What should I do? Change the charset to ISO-8858-1? I have already done this but it appears everything wrong like this:

EDIT

In addition, when I change it to missão for example it displays missão instead of missão. Besides, I can't change it manually 'cause it is in the database, I need sort of a function which will handle this

EDIT 2

I changed the special character in my database like çã to çã and now the HTML is rendering fine. Although, I'm using the Zend_Navigation for breadcrumb and it's rendering missão instead of missão just like this:

I also wrote a XML file using Zend_Config_Writer_Xml and I see it printed <label>Informa&#xE7;&#xF5;es</label> instead of <label>Informações</label>. Just in case that helps

How should I proceed?


回答1:


Here's a really good article that helped me when I started web development. I work in a multilingual environment so I bump into this stuff constantly (just to add to how great the article was :)

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

I always make sure that my files are saved in UTF8 line encoding, that my php header files declare the charset as utf8, that my db uses utf8_general_ci for it's collation, and that my html head tag contains the meta tag declaring the content as utf8. I think that covers it.

HTH :)

edit: just to add (to be more aimed at your specific problem) check to see if your PHP code treats your results as utf8. The data might be stored correctly on the DB but could be converted when it's being served.




回答2:


Make sure that your database uses the UTF-8 charset AND your database connection (the encoding in which the chars are transferred between MySQL and your PHP code) is UTF-8 (see this post for reference).

Also note, that some string operations in PHP break UTF8 encoded strings ebcause they work on the assumption "1 char = byte" which is not true with UTF 8. htmlspecialchars won't work with UTF-8 encoded strings.




回答3:


Try changing .php file encoding - open up .php file and save it (or overwrite it) as utf8 file. Hope it helps.



来源:https://stackoverflow.com/questions/4135374/how-to-handle-with-foreign-languages

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