I have Javascript in an XHTML web page that is passing UTF-8 encoded strings. It needs to continue to pass the UTF-8 version, as well as decode it. How is it possible to decode a UTF-8 string for display?
<script type="text/javascript">
// <![CDATA[
function updateUser(usernameSent){
var usernameReceived = usernameSent; // Current value: Größe
var usernameDecoded = usernameReceived; // Decode to: Größe
var html2id = '';
html2id += 'Encoded: ' + usernameReceived + '<br />Decoded: ' + usernameDecoded;
document.getElementById('userId').innerHTML = html2id;
}
// ]]>
</script>

metatag like<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />and XML declaration like<?xml version="1.0" encoding="UTF-8"?>.encodeURIComponent()anddecodeURIComponent()will assume the data is UTF-8 encoding.utf8_encode. Do you need it? Do you know why you need it?utf8_encode. Not necessarily.utf8_encodetransforms the encoding of a string from ISO 8859-1 to UTF-8. It tries to do that even if the string is already UTF-8. UTF-8 "Größe" →utf8_encode→ "GröÃe" →utf8_encode"GröÃÂe". If you apply it when you don't need it, your string screws up.