繁体   English   中英

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

[英]Why does PHP's urlencode use different URL encoding?

η的URL编码是%CE%B7 但在PHP中,当我写echo urldecode("%ce%b7");时,我会得到一些奇怪的符号echo urldecode("%ce%b7");

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

问题是我们使用typo3。 它有些如何不使用unicode进行内部处理。 一旦我们设置$TYPO3_CONF_VARS['BE']['forceCharset'] = 'utf-8'; 在typo3中输出echo urldecode("%ce%b7"); 是对的。

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

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

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

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

您可以尝试以下方法

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

观看现场演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM