PHP - urldecode. Different behavior with Wikipedia
all. I have different behavior of function urldecode() in PHP 5.2.x. Especially you will be able to see it with Wikipedia as good example.
Firstly, my page where I have results of that function has meta:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
Than I'm using function:
$url = urldecode($url);
echo $url;
Here is example of $url variable:
http://ru.wikipedia.org/wiki/%D0%91%D1%80%D0%B5%D1%81%D1%82
It will be decoded good. Result: "Брест"
http://ru.wikipedia.org/wiki/%CC%EE%EB%EE%E4%E5%F7%ED%EE
It will not be converted good. Result: ���������, but should be "Молодечно".
What's wrong? Why? I'm tried to use all functions from function.urldecode.php at PHP web-site, but it didn't give me any successful results
Here is quick example of code to test in PHP:
<?php
$url = array();
$url[] = "http://ru.wikipedia.org/wiki/%D0%91%D1%80%D0%B5%D1%81%D1%82";
$url[] = "http://ru.wikipedia.org/wiki/%CC%EE%EB%EE%E4%E5%F7%ED%EE";
foreach ($url as $value) :
echo urldecode($value) . "<br/>";
endforeach;
?>
Thanks开发者_如何学C in advance!
Not sure where you've taken that url, but the correct utf-8 one for "Молодечно" is:
$url = 'http://ru.wikipedia.org/wiki/%D0%9C%D0%BE%D0%BB%D0%BE%D0%B4%D0%B5%D1%87%D0%BD%D0%BE';
echo urldecode($url);
Your one is cp1251 encoded
As said zerkms, the following url is cp1251 encoded. To convert it to UTF-8, just use this:
$url = 'http://ru.wikipedia.org/wiki/%CC%EE%EB%EE%E4%E5%F7%ED%EE';
echo iconv("Windows-1251","UTF-8",urldecode($url));
//output: Молодечно
精彩评论