PHP Unicode Problem with AJAX

Discussion in 'PHP' started by Galaxian, Jun 30, 2010.

  1. #1
    Simply I have a text box and I want users to be able to use unicode characters.

    When submitted, jQuery posts it to the page that handles the request and escape()'s the data.

    $.post('ajax/postlike.php', { statement: escape(pstatement) },  function(data){
    Code (markup):
    All is fine, but if a unicode character is submitted, then we get problems.

    For example, if I submit "I’m testing this script. ♥"

    It will come out as "I%u2019m testing this script. %u2665"

    If I use encodeURIcomponent instead of escape, it comes out a bunch of jumble, such as the yen sign etc.

    The code that parses the request goes as following:

    $_POST['statement'] =  trim(addslashes(htmlentities(urldecode($_POST['statement']))));
    PHP:
    Any suggestions?
     
    Galaxian, Jun 30, 2010 IP