How do I get the glyph for a character encoded as "ō" from a utf-8 encoded database field using php?

I have a MySQL database table with collation 'utf8_general_ci' and the value in a field:

x and # 299; bán yá wén (no spaces).

When this is converted (for example by the StackOverflow editor) it looks like this:

xī bán yá wén

where the second character looks like lowercase i with the barbell on top.

In PHP, which function converts and # 299; object to symbol ??

I have tried using html_entity_decode ($ str, ENT_COMPAT, 'UTF-8'), however I get the following characters:

yÄ "n wén or zhÅ • ng wén

I'm sure I don't understand something about decoding, so I am using the wrong function. Can anyone shed some light on how to get the single token represented by entity and # 299 and similar characters with more characters above 255?

Thanks a lot, AE

+2


a source to share


2 answers


UTF-8 is a multibyte encoding . Thus, if you look at it with a single-byte encoding like Latin-1, you will see something similar to the results you are seeing. Set the document encoding to UTF-8 to see the actual character.



As for your first question, it is actually a browser that decodes the symbol reference and prints the symbol, not PHP.

+1


a source


I suggest you read this page: Unicode for the Working PHP Programmer . It's short-lived and should get you over hump and confident Unicode and UTF-8.



Once you get the hang of it, have a look at the mbstring and intl PHP Extensions which are very handy. And you know what PHP string functions are and are not safe for use in multibyte strings. Here's the notes I took when I was translating the site to UTF-8, which includes a list of naughty string functions.

0


a source







All Articles