为什么PHP的urlencode使用不同的URL编码?

时间:2012-10-16 14:26:04

标签: php unicode typo3 urlencode

η的URL编码是%CE%B7。但是在PHP中,当我写echo urldecode("%ce%b7");

时,我会得到一些奇怪的符号

相反,如果我写echo urlencode("η");,那么我得到%26%23951%3B。为什么我不能使用%CE%B7

解决方案

问题是我们使用拼写错误3。它有些如何不使用unicode进行内部处理。只要我们在拼写错误3中设置$TYPO3_CONF_VARS['BE']['forceCharset'] = 'utf-8';echo urldecode("%ce%b7");的输出就是正确的。

为什么echo urlencode("η");给我%26%23951%3B看到了Joni的答案。

2 个答案:

答案 0 :(得分:7)

urldecode("%ce%b7")生成以UTF-8 编码的η。如果您使用其他编码查看输出,您可能会看到其他内容。

另一方面,当您解码%26%23951%3B时,您确实没有获得η;获得η,它是η的HTML实体代码。要解码实体代码,请使用html_entity_decode

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

答案 1 :(得分:2)

您可以尝试以下

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

See Live Demo