I want to decode a string like c'è in utf8.
When encoding or / and decoding from one to another character-set is m开发者_如何学Goade, typical strings appear that show that something went wrong. Is it possible for the posted string to reconstruct the origin utf-8 string?If you mean to change 'strange' characters like ä Ü into their equivalents a U, then this might help:
PHP Normalizer class
It is hard to say what you mean with “decoding” the string. A string in UTF-8 is just a valid string as it stands. You can convert it to another encoding, but you do not state which one you want to use. So, to convert a string from one encoding (e.g. UTF-8) to another (e.g. iso-8859-2), you can use e.g. the iconv()
function, e.g.:
iconv("UTF-8", "ISO-8859-2", $text)
But be aware that there are many characters in Unicode (and UTF-8) which cannot be represented in a particular single-byte character set; check the PHP documentation for your options in such cases. (You might be able to just use the string in UTF-8, which is probably the best encoding available, anyway.)
If I do:
$string="c'è";
echo mb_detect_encoding($string);
I'd get:
UTF-8
精彩评论