0

I want to encode a string with a heart ❤ emoji in js:

php utf8_encode produces: \u2764

js utf8.encode produces: â¤

are both values valid when I use them in a response with utf header:

"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"
adiga
  • 34,372
  • 9
  • 61
  • 83
Chris
  • 13,100
  • 23
  • 79
  • 162
  • Do not use PHP's `utf8_encode()` or `utf8_decode()` functions unless you: 1. Are converting between ISO8859-1 and UTF-8. 2. Are explicitly certain that the input encoding is correct. If either of those are not true these functions will happily corrupt your data. Better yet, _never_ use these poorly-named functions and use [`mb_convert_encoding()`](https://secure.php.net/manual/en/function.mb-convert-encoding.php) with explicitly-defined input and output encodings. – Sammitch Feb 22 '19 at 19:15
  • Also, emojis are never _not_ UTF-8, and `\u2764` is the result of passing the emoji through `json_encode()` which escapes high-order codepoints. `â¤` is likely the result of attempting to view the correct UTF-8 byte sequence under an incorrect encoding. https://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Sammitch Feb 22 '19 at 19:18

0 Answers0