kckern Posted February 3, 2009 Share Posted February 3, 2009 I have a page that is encoded with charset=utf-8. The page has some Asian language characters which display just fine, thanks to utf-8 encoding. I am scraping a data string off an external page. This page is encoded with charset=ks_c_5601-1987, aka EUC-KR. When I display the scraped data string on my page utf-8 page, question blocks appear, indicating that the browser cannot understand the encoding. If I change my browser to View->Character Encoding->Korean (EUC-KR), the scraped data string appears correctly. This confirms that the data being scraped has arrived intact. However, the rest of the original Asian characters on the page (the ones originally encoded with UTF- get scrambled. So, I have a php string encoded in EUC-KR, and I want to place it on a UTF-8 page. The two don't seem to get along. I tried utf8_encode(), but it only supports ISO-8859-1 input, not EUC-KR. I tried htmlentities(), which supports more encodings, but not EUC-KR. The only thing that seems to do anything is breaking the string down to hex bytes. urlencode() and a custom string_to_hex() function give me a hash of the characters, but they don't correctly correspond up to any characters in any unicode hex table I've been able to find. Thus, I can get a hex value from the string, but I have no way to transform that into a utf-8 encoded string. This is kind of driving me crazy! There doesn't seem to be a single function anywhere that can input EUC-KR and output UTF-8! Yet somehow, the browser is able to correctly render the character when I switch the page encoding view! What is it the browser is doing to the entire page that that my php engine can't do to the string? ??? Changing the entire page encoding to EUC-KR is not an option: too much of the site's infrastructure is established in utf-8. I just need to get this darn string to conform to the rest of the page. For the love of all that's holy to you, IS THERE NO WAY TO DECODE THIS STRING?? Quote Link to comment https://forums.phpfreaks.com/topic/143565-encoding-to-utf-8/ Share on other sites More sharing options...
MadTechie Posted February 3, 2009 Share Posted February 3, 2009 Have you tried echo iconv("ks_c_5601-1987", "UTF-8", "Scrapped stuff"); Quote Link to comment https://forums.phpfreaks.com/topic/143565-encoding-to-utf-8/#findComment-753400 Share on other sites More sharing options...
kckern Posted February 3, 2009 Author Share Posted February 3, 2009 Bless your heart, MadTechie! I tried echo iconv("EUC-KR", "UTF-8", $string); and it did exactly what I wanted! I had never heard of the iconv function despite hours of searching. Thank you so very much! Quote Link to comment https://forums.phpfreaks.com/topic/143565-encoding-to-utf-8/#findComment-753554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.