简体   繁体   English

为什么我的PHP urlencode无法在互联网上用作示例?

[英]Why is my PHP urlencode not functioning as examples on internet?

Why does my urlencode() produce something different than I expected? 为什么我的urlencode()产生与预期不同的东西?

This might be my expectations being wrong but then I would be even more puzzled. 这可能是我的期望是错误的,但随后我会更加困惑。

example

urlencode("ä");

expectations = returns %C3%A4

reality = returns %E4

Where have I gone wrong in my expections? 我在哪里出了错? It seems to be linked to encoding. 它似乎与编码有关。 But I'm not very familiar in what I should do/use. 但是我对应该做什么/使用不是很熟悉。

Should I change something on my server to that the function uses the right encoding? 我应该在服务器上更改一些功能以使用正确的编码吗?

urlencode encodes the raw bytes in your string into a percent-encoded representation. urlencode将字符串中的原始字节编码为百分比编码的表示形式。 If you expect %C3%A4 that means you expect the UTF-8 byte representation of "ä". 如果您期望%C3%A4 ,则意味着您期望UTF-8字节表示形式为“ä”。 If you get %E4 that means your string is actually encoded in ISO-8859-1 instead. 如果您获得%E4 ,则表示您的字符串实际上是在ISO-8859-1中编码的。

Encode your string in UTF-8 to get the expected result. 将字符串编码为UTF-8以得到预期的结果。 How to do this depends on where this string comes from. 如何执行此操作取决于此字符串的来源。 If it's a string literal in your source code file, save the file as UTF-8 in your text editor. 如果它是源代码文件中的字符串文字,请在文本编辑器中将文件另存为UTF-8。 If it comes from a database, see UTF-8 all the way through . 如果它来自数据库,请始终参阅UTF-8

For more background information, see What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text . 有关更多背景信息,请参阅每个程序员绝对肯定要了解有关使用文本的编码和字符集的知识

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

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