Using Javascript’s atob to decode base64 doesn’t properly decode utf-8 strings

The Unicode Problem Though JavaScript (ECMAScript) has matured, the fragility of Base64, ASCII, and Unicode encoding has caused a lot of headache (much of it is in this question’s history). Consider the following example: const ok = “a”; console.log(ok.codePointAt(0).toString(16)); // 61: occupies < 1 byte const notOK = “✓” console.log(notOK.codePointAt(0).toString(16)); // 2713: occupies > 1 … Read more

How can I output a UTF-8 CSV in PHP that Excel will read properly?

I have the same (or similar) problem. In my case, if I add a BOM to the output, it works: header(‘Content-Encoding: UTF-8’); header(‘Content-type: text/csv; charset=UTF-8’); header(‘Content-Disposition: attachment; filename=Customers_Export.csv’); echo “\xEF\xBB\xBF”; // UTF-8 BOM I believe this is a pretty ugly hack, but it worked for me, at least for Excel 2007 Windows. Not sure it’ll … Read more

How to convert a string to utf-8 in Python

In Python 2 >>> plain_string = “Hi!” >>> unicode_string = u”Hi!” >>> type(plain_string), type(unicode_string) (<type ‘str’>, <type ‘unicode’>) ^ This is the difference between a byte string (plain_string) and a unicode string. >>> s = “Hello!” >>> u = unicode(s, “utf-8”) ^ Converting to unicode and specifying the encoding. In Python 3 All strings are … Read more

HTML encoding issues – “” character showing up instead of ” “

Somewhere in that mess, the non-breaking spaces from the HTML template (the  s) are encoding as ISO-8859-1 so that they show up incorrectly as an “” character That’d be encoding to UTF-8 then, not ISO-8859-1. The non-breaking space character is byte 0xA0 in ISO-8859-1; when encoded to UTF-8 it’d be 0xC2,0xA0, which, if you (incorrectly) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)