The documentation on this page http://ru2.php.net/manual/en/function.urldecode.php says that "The superglobals $_GET and $_REQUEST are already decoded".
But on my server this code
var_dump($_GET['str'])
returns
string(21) "ффф"
How can I make php decode strings in $_GET ?
You should set correct header content-type on pages with form:
header('Content-Type: text/html; charset="UTF-8"');
And you should get correct data from $_GET without any decoding operations.
That is decoded. The value is already decoded from its URL percent encoded form. The original was likely:
%26%231092%3B%26%231092%3B%26%231092%3B
It has now been decoded to:
ффф
The content of the string is escaped HTML. If you're sending escaped HTML, you'll get escaped HTML. If you don't like escaped HTML, don't send escaped HTML. PHP is not going to try every possible encoding format recursively on URL values until nothing more can be decoded.
As @deceze states, that string already is decoded. But if you want to transform it into readable characters, use html_entity_decode()
.
$string = 'ффф';
echo html_entity_decode($string);
returns
ффф
Example: http://3v4l.org/eqDf3
The number after &#
is a decimal unicode code-point which is unrelated to UTF-8.
According to http://www.utf8-chartable.de/unicode-utf8-table.pl?start=1024&number=1024&unicodeinhtml=dec, your character is:
U+0444 ф d1 84 ф ф CYRILLIC SMALL LETTER EF
Here, d1 84
is the UTF-8 representation for it.
As mentioned earlier, html_entity_decode("ффф", null, 'UTF-8')
should do the trick.
It returns the following string:
'ÐäÐäÐä'
Which hexadecimal representation can be found like this:
>> bin2hex($s)
'd184d184d184'
It is indeed correct according to the table quoted previously.