0

I have a test text which i post with and ajax call (JQuery):

čéáűőúöüó é$ߤ÷׸¨¸˝¨´~˘˝°´˛>*čéáűőúöüó$>*ß$÷×÷;$¨˝´>$đ;ä

i just write the very same text in the response

<?php 
$text=$_POST["text"];
echo "\n\nUTF8_DECODE:\n";
echo utf8_decode($text);
echo "\nISO8859-2 -> UTF-8:\n";
echo iconv("ISO-8859-2","UTF-8",$text);
echo "\nUTF-8 -> ISO-8859-2 \n";
echo iconv("UTF-8","ISO-8859-2",$text);
 ?>

The result should be:

UTF8_DECODE:

?éá??úöüó é$ߤ÷׸¨¸?¨´~??°´?>*?éá??úöüó$>*ß$÷×÷;$¨?´>$?;ä

ISO8859-2 -> UTF-8:

čéáűőúöüó é$ߤ÷׸¨¸˝¨´~˘˝°´˛>*čéáűőúöüó$>*ß$÷×÷;$¨˝´>$đ;ä

UTF-8 -> ISO-8859:

ĂÂÄĹ ÄÄÄšÄÄšÂÄĹÄĹÄĹşÄĹ ÄĹ $ÄÂäÄËÄÂøèøĂÂèô~ĂÂĂÂðôĂÂ>*ĂÂÄĹ ÄÄÄšÄÄšÂÄĹÄĹÄĹşÄĹ$>*ÄÂ$ÄËÄÂÄË;$èĂÂĂ´>$ĂÂ;Ĥ

But it is:

UTF8_DECODE:

?éá??úöüó é$ߤ÷׸¨¸?¨´~??°´?>*?éá??úöüó$>*ß$÷×÷;$¨?´>$?;ä

ISO8859-2 -> UTF-8:

ĂÂÄĹ ÄÄÄšÄÄšÂÄĹÄĹÄĹşÄĹ ÄĹ $ÄÂäÄËÄÂøèøĂÂèô~ĂÂĂÂðôĂÂ>*ĂÂÄĹ ÄÄÄšÄÄšÂÄĹÄĹÄĹşÄĹ$>*ÄÂ$ÄËÄÂÄË;$èĂÂĂ´>$ĂÂ;Ĥ

UTF-8 -> ISO-8859-2:
čéáűőúöüó é$ߤ÷׸¨¸˝¨´~˘˝°´˛>*čéáűőúöüó$>*ß$÷×÷;$¨˝´>$đ;ä

My question is why is that?? What i miss? Because my text is at ISO-8859-2 and i want to transfer to UTF-8, why i need to use the opposite method when:

string iconv ( string $in_charset , string $out_charset , string $str )

Performs a character set conversion on the string str from in_charset to out_charset.

Maybe the ajax request encoded in UTF-8 the ISO-8859-2 characters?

Community
  • 1
  • 1
czupe
  • 4,740
  • 7
  • 34
  • 52
  • 1
    It looks like `$_POST["text"]` is in utf8 not `ISO-8859-2` – Musa Jul 13 '13 at 20:24
  • Yeah, seriously it looks like, maybe the jQuery ajax option: contentType: "application/x-www-form-urlencoded;charset=UTF-8", finally do something... But still pretty weird this whole story for me... And thanks for your time! – czupe Jul 13 '13 at 20:31
  • The only solution now i have to my encoding problem is that - i encoded the iso-8859-2 to UTF-8 at client side (with JQUERY) then send it to the PHP with AJAX - than decoded with PHP and send it back, now the result seems OKish... But this seems a not elegant solution. What do you think? – czupe Jul 13 '13 at 20:34

0 Answers0