1

I'm getting a textarea value with jQuery and using ajax to post it to the server.

I'm using escape(textarea.val()) to encode the URL in jQuery.

In my PHP script, I'm using rawurldecode to convert it back.

This works for every character on my keyboard except the euro sign (€). Instead, it returns the hex code (%u20AC).

I have no idea how to fix this, as far as I know all my charset settings are in order.

Thanks

bur
  • 604
  • 5
  • 20

2 Answers2

1

%u20AC is Unicode-encoded data for which is generated by JavaScript's escape() function to UTF8 for server-side processing.

Standard PHP urldecode can not deal with it, so you need to use an extended routine:

/**
 * @param string $str unicode and ulrencoded string
 * @return string decoded string
 */
function utf8_urldecode($str) {
    $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));
    return html_entity_decode($str,null,'UTF-8');;
}

Source : UTF-8 Encoding with internet explorer %u20AC to €

Community
  • 1
  • 1
Subir Kumar Sao
  • 8,171
  • 3
  • 26
  • 47
  • thanks, I switched encodeURIComponent in my ajax request :) now it's properly encoding – bur Oct 22 '12 at 09:25
0

Your jQuery script is not sending data through according to RFC3986.

%u20AC is not URL encoding.

CAMason
  • 1,122
  • 7
  • 13
  • HTML escaping is `€`, **not** `%u20AC` – Alvin Wong Oct 22 '12 at 09:14
  • 1
    I just spent hours trying to make this work. One of the first things I did was use encodeURIComponent instead of escape, which didn't work. Now I did it again because of y our answer, and it works! I must have done something in those hours that has made this work. Thanks! – bur Oct 22 '12 at 09:24