1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

utf-8 letters with JS and PHP

Discussion in 'Programming' started by yandos, Feb 11, 2010.

  1. #1
    Hi all,

    I'm having a problem with java script, PHP and utf-8...
    I've made a little auto completer that uses AJAX.
    it works great with English letters, but when I enter text in any other language it doesn't work.

    I know the JS handles the input ok, because if I ask it to repeat the text it will.
    but when it gets to the client side, my php file, it simply disappears. I've tried to echo the var that comes from the JS - but nothing, empty string...

    If i put a mixed input of english and non-latin chars, I get squares insted of the non-latin chars, and the english chars are ok.

    I'm new to programming so it might be something silly :). even if its an obvious idea - please tell me because I might not know it yet :)...
    thanks,
    Yandos.
     
    yandos, Feb 11, 2010 IP
  2. po_taka

    po_taka Peon

    Messages:
    14
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    use:
    encodeURIComponent(string);
     
    po_taka, Feb 12, 2010 IP
  3. yandos

    yandos Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi and thanks for the help :)
    i've added it and checked that it is encoded alright (and it does).... but still it dosn't work.
    I think I need to somehow decode it. googled it and found two options that didn't work for me:
    $namecard  = htmlspecialchars($namecard , ENT_QUOTES, 'utf-8');                           
    HTML:
    and also another function:
    htmlentities($str);
    HTML:
    any ideas maybe?
     
    yandos, Feb 12, 2010 IP
  4. bogdanas

    bogdanas Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You need to configure webserver to use default charset as UTF-8, in Ubuntu + Apache2 it is done by editing file /etc/apache2/conf.d/charset
     
    bogdanas, Feb 16, 2010 IP