Question

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

Was it helpful?

Solution

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

%u20AC is not URL encoding.

OTHER TIPS

%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 €

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top