Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to convert ISO8859-1 encoded text feed to UTF-8 before displaying using JavaScript?

I embedded a short script into a client's website which is grabbing text feed content from a 3rd party. The result is 5 links encoded in ISO8859-1. Since the whole website has UTF-8 French content, this feed is creating artifacts.

Is there any way to use JavaScript / jQuery to convert the ISO feed to UTF and then display everything on the website properly?

Thanks!

EDIT

The solution in my case was actually easy. All I have done was to add charset='ISO8859-1' into the JavaScript that was pulling news feed. I hope this will help someone.

like image 611
Klikerko Avatar asked Dec 12 '11 18:12

Klikerko


People also ask

What is the difference between ISO 8859 1 and UTF-8?

UTF-8 is a multibyte encoding that can represent any Unicode character. ISO 8859-1 is a single-byte encoding that can represent the first 256 Unicode characters. Both encode ASCII exactly the same way.

How do I convert UTF-8 to ISO 8859 1?

byte[] utf8 = ... byte[] latin1 = new String(utf8, "UTF-8"). getBytes("ISO-8859-1"); You can exercise more control by using the lower-level Charset APIs. For example, you can raise an exception when an un-encodable character is found, or use a different character for replacement text.

How is UTF-8 encoded?

UTF-8 encodes a character into a binary string of one, two, three, or four bytes. UTF-16 encodes a Unicode character into a string of either two or four bytes. This distinction is evident from their names. In UTF-8, the smallest binary representation of a character is one byte, or eight bits.

How to encode string to UTF-8 in php?

PHP | utf8_encode() Function The utf8_encode() function is an inbuilt function in PHP which is used to encode an ISO-8859-1 string to UTF-8. Unicode has been developed to describe all possible characters of all languages and includes a lot of symbols with one unique number for each symbol/character.


1 Answers

Add charset='ISO8859-1' into the JavaScript that pulls the news feed.

like image 135
Anthony Faull Avatar answered Oct 06 '22 23:10

Anthony Faull