When I type in Firefox (in the address line) URL like [http://www.example.com/?query=Траливали](http://www.example.com/?query=%D0%A2%D1%80%D0%B0%D0%BB%D0%B8%D0%B2%D0%B0%D0%BB%D0%B8), it is automatically encoded to <http://www.example.com/?query=%D2%F0%E0%EB%E8%E2%E0%EB%E8>.

But URL like [http://www.example.com/#ajax\_call?query=Траливали](http://www.example.com/#ajax_call?query=%D0%A2%D1%80%D0%B0%D0%BB%D0%B8%D0%B2%D0%B0%D0%BB%D0%B8) is not converted.

Other browsers such as IE8 do not convert query at all.

The question is: how to detect (in PHP) if query is encoded? How to decode it?

I've tried:

1. $str = iconv('cp1251', 'utf-8', urldecode($str) );
2. $str = utf8\_decode(urldecode($str));
3. $str = (urldecode($str));
4. many functions from <http://php.net/manual/en/function.urldecode.php>
Nothing works.

Test:

> 
> $str = $\_GET['str'];
> 
> 
> d('%D2%F0%E0%EB%E8%E2%E0%EB%E8' == urldecode('%D2%F0%E0%EB%E8%E2%E0%EB%E8'));
> 
> 
> d('%D2%F0%E0%EB%E8%E2%E0%EB%E8' == $str);
> 
> 
> d('Траливали' == $str);
> 
> 
> d(urldecode($str));
> 
> 
> d(utf8\_decode(urldecode($str)));
> 
> 
> !!! d('%D2%F0%E0%EB%E8%E2%E0%EB%E8' == urlencode($str)); !!!
> 
> 
> 

Returns:

[false]
[false]
[false]
���������
????
[true]

Some kind of a solution: [http://www.example.com/Траливали/](http://www.example.com/%D0%A2%D1%80%D0%B0%D0%BB%D0%B8%D0%B2%D0%B0%D0%BB%D0%B8/) - send a query as a url part and parse with mod\_rewrite.