4

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.

0

2 Answers 2

7

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
Sign up to request clarification or add additional context in comments.

4 Comments

Unfortunately, echo html_entity_decode('η', false, 'UTF-8'); does not print η. I have already header('Content-Type: text/html; charset=utf-8'); included. And the browser pretends to show it in unicode. Actually, echo urldecode("%26%23951%3B"); prints η.
Actually, echo urldecode("%26%23951%3B") prints η. If you happen to be viewing the result in a web browser, the browser shows this sequence of multiple characters as η. As to why the browser refuses to show a correctly encoded UTF-8 character despite the Content-Type header, it's hard to tell without seeing the page.
ok, now I see my problem. Thanks for pointing that out. But I still don't understand why echo urldecode("%ce%b7"); is not displayed correctly.
It's hard to say without seeing the page. Maybe there's some non-UTF-8 text that makes the browser think the page is not encoded in UTF-8?
2

You can try the following

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

See Live Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.