So What Software

Tag: decode

UTF8 Encode/Decode Problems

by on Feb.07, 2010, under Programming

I decided a bit late to make my new PHP project language aware. After designing a language system which consisted of a central text dispatcher and of course, language specific text files, or as was at first MySQL databases tables. (I switched to arrays instead of database tables to avoid “too many connections” errors.) It works by basically maintaining a cookie with the desired language code and using that information to point to or more exactly, require the proper text array when text is needed in the webpage. All text data files are keyed by the language code: (mytextfile_en.php) for english etc… Most everything worked fine but not everything. Seems I had encoding problems with UTF8 in languages that use diacriticals and whatnot. I eventually solved this problem with two distinct alterations.

1. I went through the code and made sure each and every charset= declaration was utf8 (charset=utf8). This includes any ajax handlers both up and down paths. I was amazed at the various charset’s that were in my code, few if any were already utf8. iso-8859-1 and tis-620 were all over the place and are not really Unicode compatible. Once I got that all straightened out everything worked perfect… well almost perfect.

2. This brings us to solution #2. In situations where an ajax handler generated a pop-up list or even straight text from an array there was still an encode/decode problem. I fixed this by implicitly doing a utf8_encode() on the values in these arrays. In my code it looked like this: utf8_encode(getTxt(‘TX1234′))… the TX1234 is an example of my own index code for the various text elements and the getTxt() is my text dispatcher. I did not have to do this force for any other method of text passing, only the ajax array generated text. Don’t really know exactly why this is, but it is, so there you are, and that’s it!

Comments Off :, , , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...