I’m making a KSSN (Korean ID Number) checker in PHP using a MySQL database.
I check if it is working by using a file_get_contents call to an external site.
The problem is that the requests (with Hangul/Korean characters in them) are using the wrong charset.
When I echo the string, the Korean characters just get replaced by question marks.
How can I make it to use Korean? Should I change anything in the database too?
What should be the charset?
PHP Source and SQL Dump: http://www.multiupload.com/RJ93RASZ31
NOTE: I’m using Apache (HTML), not CLI.
You need to:
tell the browser what encoding you wish to receive in the form submission, by setting
Content-Typeby header or<meta>as in aviv’s answer.tell the database what encoding you’re sending it bytes in, using
mysql_set_charset().Currently you are using EUC-KR in the database so presumably you want to use that encoding in both the above points. In this century I would suggest instead using UTF-8 throughout for all web apps/databases, as the East Asian multibyte encodings are an anachronistic unpleasantness. (With potential security implications, as if
mysql_real_escape_stringdoesn’t know the correct encoding, a multibyte sequence containing'or\can sneak through an SQL injection.)However, if enpang.com are using EUC-KR for the encoding of the
NameURL parameter you would need either to stick with EUC-KR, or to transcode the name value from UTF-8 to EUC-KR for that purpose usingiconv(). (It’s not clear to me what encoding enpang.com are using for URL parameters to their name check service; I always get the same results anyway.)