Jump to content

Encoding to UTF-8


kckern

Recommended Posts

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-8) 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??

 

Link to comment
https://forums.phpfreaks.com/topic/143565-encoding-to-utf-8/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.