1

I'd like to convert character encoding of a string to HTML-ENTITIES and then back to utf-8. I thought that converting to some encoding and back should leave me with the same string, but it doesn't look like it.

My testing string is:

Test: ěščřžýáíé'

Conversion to HTML-ENTITIES

echo mb_convert_encoding('Test: ěščřžýáíé', 'HTML-ENTITIES', 'UTF-8');

outputs this result:

Test: ěščřžýáíé

However when I try to convert back to utf-8

echo mb_convert_encoding('Test: ěščřžýáíé', 'UTF-8', 'HTML-ENTITIES');

I surprisingly get (incorrect) ouput, not the original string:

Test: ěščřžýáíé

How can I properly convert encodings to get my original string back?

feek
  • 11
  • 4
  • Works for me. You should double-check that the display encoding for your final output is UTF-8 and not something else. eg: your browser is set to auto-detect and is using ISO-8859. http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Sammitch Jun 23 '16 at 18:34
  • @Sammitch Oh, you're right of course. I forgot to set the display encoding of my testing page properly and Firefox defaulted to something else _facepalm_. Thank you! – feek Jun 23 '16 at 18:49

0 Answers0