Why is php not decoding this unicode it usually does?

Discussion in 'PHP' started by gandalf117, Sep 10, 2009.

  1. #1
    Hi, everyone

    This is my first question here. Even though it is far from one of the hard ones I usually ask it is very challenging and has been bugging me for the last couple of hours. Here is the deal:

    I have a MySql database that keeps non-Latin text in the form of Unicode (correct me if I am wrong, I believe it's Unicode). For example in a table under column "name" instead of "John" one my find:
    & #1051;& #1086;& #1082;& #1086;& #1084;& #1086;& #1090;& #1080;& #1074; & #1057;& #1086;& #1092;& #1080;& #1103;
    (without the spaces between & and #)
    when decoded this string spells "Локомотив" in Cyrillic (google it if you don't believe me).
    When selected from the database and output directly to the screen with
    <?php echo $string; ?> it displays properly in decoded format - "Локомотив". But when I make a simple AJAX request with javascript <?php echo $string; ?> returns the encoded version you saw first. What is going on?

    How come php haven't decoded the string when javascript makes the request?
    How come php outputs it properly in a browser with Character Encoding set to Western (ISO-8859-1) without any decoding in the first place?
    Is there a function in php or javascript that can help me decode this row of numbers?
     
    Last edited: Sep 10, 2009
    gandalf117, Sep 10, 2009 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    wd_2k6, Sep 10, 2009 IP
  3. superdav42

    superdav42 Active Member

    Messages:
    125
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    I'm not entirely sure what the issue is but I can tell you it's not a php problem. PHP is not evolved in converting those codes to their equivalent unicode characters but it is done by the browser. Just try saving the hex codes in a plain html file and you will see them being converted to their unicode characters. It seems for some reason when using javascript on your page the browser is no longer interpreting the hex codes like it usually would. If you could show us the resulting html code that does not work we could probably help you out.
     
    superdav42, Sep 10, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I believe all ajax requests are in utf-8, look it up. This may be the source of the error.
     
    premiumscripts, Sep 10, 2009 IP