Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UTF-8 to readable characters [duplicate]

Tags:

javascript

Encoding and decoding a string is not as easy as I thought.

The original string is as follows:

at the end of → al término de • después de

After PHP base64 encoding (used three times) it looks different:

VUVkSksxbFlVV2RrUjJoc1NVZFdkVnBEUW5aYWFuZDJXV28wWnpSdllWTkpSMFp6U1VoVVJIRllTblJoVnpWMlNVZFNiRWxQUzBGdmFVSnJXbGhPZDJSalQzQmplVUpyV2xSNGQxQm5QVDA9

When trying JS window.atob() to decode the string, the result is this:

at the end of â al término de ⢠después de

UTF-8 characters are not displayed properly. What function should I use to fix this?


1 Answers

Try

let decodedString = decodeURIComponent(escape(window.atob(yourString)))
like image 113
Turan Avatar answered Mar 28 '26 19:03

Turan