Truppe Steven wrote:
> Mark Gibson schrieb:
> 
>> Javascript has the functions:
>>
>> decodeURI(s) and decodeURIComponent(s)
>>   
> I get a string like this:
>       
> Stumpf+einer+Palme%2C+ausgeh%F6hlt%2C+geschliffen+und+mit+Perlmutteinlegearbeiten+verziert
> 
> If this string is inside the variable "test" and i do:
>       var newtest = decodeURIComponent(test);
> 
> I get the error "malformed URI sequence".
> 
> I've looked documentation on 
> http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference
> but there i don't see much about that function...
> 
> Thanks for the fast reply! What am i doing wrong ?

decodeURIComponent("Stumpf+einer+Palme%2C+ausgehhlt%2C+geschliffen+und+mit+Perlmutteinlegearbeiten+verziert")
(%F6 taken out) produces:
"Stumpf+einer+Palme,+ausgehhlt,+geschliffen+und+mit+Perlmutteinlegearbeiten+verziert"

It's definitely the %F6 part. Also PHP's urlencode() appears to be 
converting spaces to +, try using rawurlencode() instead, or
in JS replace + with %20:

decodeURIComponent(test.replace(/\+/g,'%20'))

I'm not sure what to do with non-ascii characters like the %F6 in URIs,
I think you'd need to use IRI's (internationalized URI's), but I can't
help you there I'm afraid - I don't think PHP or JS supports them!

You said earlier that you urlencode() and then pass it in a JSON
serialized string, is there any reason for this?

I think you'd be better off converting the string to UTF-8 and
just passing it in the JSON string.

In PHP have a look at:
utf8_encode(), iconv, or mbstring

- Mark

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to