title: PHP UTF-encoded URL-string
body: <p>When I type in Firefox (in the address line) URL like <a href="http://www.example.com/?query=%D0%A2%D1%80%D0%B0%D0%BB%D0%B8%D0%B2%D0%B0%D0%BB%D0%B8" rel="nofollow noreferrer">http://www.example.com/?query=Траливали</a>, it is automatically encoded to <a href="http://www.example.com/?query=%D2%F0%E0%EB%E8%E2%E0%EB%E8" rel="nofollow noreferrer">http://www.example.com/?query=%D2%F0%E0%EB%E8%E2%E0%EB%E8</a>.</p>
  <p>But URL like <a href="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" rel="nofollow noreferrer">http://www.example.com/#ajax_call?query=Траливали</a> is not converted.</p>
  <p>Other browsers such as IE8 do not convert query at all.</p>
  <p>The question is: how to detect (in PHP) if query is encoded? How to decode it?</p>
  <p>I've tried:</p>
  <ol>
  <li><p>$str = iconv('cp1251', 'utf-8', urldecode($str) );</p>
  </li>
  <li><p>$str = utf8_decode(urldecode($str));</p>
  </li>
  <li><p>$str = (urldecode($str));</p>
  </li>
  <li><p>many functions from <a href="http://php.net/manual/en/function.urldecode.php" rel="nofollow noreferrer">http://php.net/manual/en/function.urldecode.php</a>
  Nothing works.</p>
  </li>
  </ol>
  <p>Test:</p>
  <blockquote>
  <p>$str = $_GET['str'];</p>
  <p>d('%D2%F0%E0%EB%E8%E2%E0%EB%E8' == urldecode('%D2%F0%E0%EB%E8%E2%E0%EB%E8'));</p>
  <p>d('%D2%F0%E0%EB%E8%E2%E0%EB%E8' == $str);</p>
  <p>d('Траливали' == $str);</p>
  <p>d(urldecode($str));</p>
  <p>d(utf8_decode(urldecode($str)));</p>
  <p>!!! d('%D2%F0%E0%EB%E8%E2%E0%EB%E8' == urlencode($str)); !!!</p>
  </blockquote>
  <p>Returns:</p>
  <p>[false]
  [false]
  [false]
  ���������
  ????
  [true]</p>
  <p>Some kind of a solution: <a href="http://www.example.com/%D0%A2%D1%80%D0%B0%D0%BB%D0%B8%D0%B2%D0%B0%D0%BB%D0%B8/" rel="nofollow noreferrer">http://www.example.com/Траливали/</a> - send a query as a url part and parse with mod_rewrite.</p>