Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does PHP's urlencode use different URL encoding?

The URL encoding of η is %CE%B7. But in PHP I get some strange symbols 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?

Solution

The Problem is that we use typo3. It some how does not use unicode for internal processing. As soon as we set $TYPO3_CONF_VARS['BE']['forceCharset'] = 'utf-8'; in typo3 the output of echo urldecode("%ce%b7"); was correct.

For why echo urlencode("η"); gives me %26%23951%3B see the answers of Joni.

like image 875
Raoul Avatar asked Jan 16 '23 07:01

Raoul


2 Answers

urldecode("%ce%b7") produces η encoded in UTF-8. If you are viewing the output with some other encoding you may see something else.

On the other hand, when you decode %26%23951%3B it's true that you don't obtain η; you obtain η which is a HTML entity code for η. To decode entity codes use html_entity_decode:

echo html_entity_decode('η', false, 'UTF-8'); // prints η, encoded in UTF-8
like image 62
Joni Avatar answered Jan 17 '23 19:01

Joni


You can try the following

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

See Live Demo

like image 29
Baba Avatar answered Jan 17 '23 21:01

Baba