[英]Why does PHP's urlencode use different URL encoding?
The URL encoding of η is %CE%B7
. η的URL编码是
%CE%B7
。 But in PHP I get some strange symbols when I write echo urldecode("%ce%b7");
但在PHP中,当我写
echo urldecode("%ce%b7");
时,我会得到一些奇怪的符号echo urldecode("%ce%b7");
Instead, if I write echo urlencode("η");
相反,如果我写
echo urlencode("η");
then I get %26%23951%3B
. 然后我得到
%26%23951%3B
。 Why can't I use %CE%B7
? 为什么我不能使用
%CE%B7
?
Solution 解
The Problem is that we use typo3. 问题是我们使用typo3。 It some how does not use unicode for internal processing.
它有些如何不使用unicode进行内部处理。 As soon as we set
$TYPO3_CONF_VARS['BE']['forceCharset'] = 'utf-8';
一旦我们设置
$TYPO3_CONF_VARS['BE']['forceCharset'] = 'utf-8';
in typo3 the output of echo urldecode("%ce%b7");
在typo3中输出
echo urldecode("%ce%b7");
was correct. 是对的。
For why echo urlencode("η");
为什么
echo urlencode("η");
gives me %26%23951%3B
see the answers of Joni. 给我
%26%23951%3B
看到Joni的答案。
urldecode("%ce%b7")
produces η encoded in UTF-8 . urldecode("%ce%b7")
产生以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 η; 另一方面,当您解码
%26%23951%3B
时,您确实没有获得η; you obtain η
你得到
η
which is a HTML entity code for η. 这是η的HTML实体代码。 To decode entity codes use
html_entity_decode
: 要解码实体代码,请使用
html_entity_decode
:
echo html_entity_decode('η', false, 'UTF-8'); // prints η, encoded in UTF-8
You can try the following 您可以尝试以下方法
header('Content-Type: text/html; charset=utf-8');
echo urldecode("%ce%b7"); // output : η
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.