Why does PHP urlencode use a different URL encoding?

URL encoding η is %CE%B7 . But in PHP, I get some weird characters when I write echo urldecode("%ce%b7");

Instead, if I write echo urlencode("η"); then I get %26%23951%3B . Why can't I use %CE%B7 ?

Decision

The problem is that we are using typo3. Some of them do not use unicode for internal processing. Once we set $TYPO3_CONF_VARS['BE']['forceCharset'] = 'utf-8'; in typo3, the output is echo urldecode("%ce%b7"); was right.

Why echo urlencode("η"); gives me %26%23951%3B see answers Johnny.

+4
source share
2 answers

urldecode("%ce%b7") creates η encoded in UTF-8. If you are viewing the output using some other encoding, you can see something else.

On the other hand, when you decode %26%23951%3B , it is true that you do not get η; you get η , which is the HTML entity code for η. To decode entity entities, use html_entity_decode :

 echo html_entity_decode('η', false, 'UTF-8'); // prints η, encoded in UTF-8 
+7
source

You can try the following

 header('Content-Type: text/html; charset=utf-8'); echo urldecode("%ce%b7"); // output : η 

See demo version

+2
source

Source: https://habr.com/ru/post/1440066/


All Articles