使用 PHP 删除编码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2418771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:24:04  来源:igfitidea点击:

Remove encoding using PHP

phpencode

提问by kylex

I have the following text:

我有以下文字:

We%27re%20proud%20to%20introduce%20the%20Amazing

I'd like to remove the encoding using PHP, but using html_entity_decode()does not work.

我想使用 PHP 删除编码,但使用html_entity_decode()不起作用。

Any suggestions?

有什么建议?

回答by erenon

echo urldecode('We%27re%20proud%20to%20introduce%20the%20Amazing');

This is an url_ecoded string. Use urldecode

这是一个 url_ecoded 字符串。用urldecode

回答by Gumbo

This encoding is called Percent encodingor URL encoding. In PHP you have rawurlencode, rawurldecodefor “raw” URL encoding as well as the urlencodeand urldecodefor the slightly different encoding that is used in the query (rather known as application/x-www-form-urlencodedwhere the space is encoded with +instead of %20).

这种编码称为百分比编码或 URL 编码。在 PHP 中rawurlencoderawurldecode对于“原始”URL 编码以及urlencodeurldecode用于查询中使用的略有不同的编码(也称为application/x-www-form-urlencoded,其中空格是用+而不是编码的%20)。

In your case the “raw” URL encoding is used. So try rawurldecodeto decode it:

在您的情况下,使用“原始”URL 编码。所以尝试rawurldecode解码它:

rawurldecode('We%27re%20proud%20to%20introduce%20the%20Amazing')

回答by jwhat

%27 and %20 are URL encoded entities.

%27 和 %20 是 URL 编码的实体。

You'll want to use use urldecode()to decode this. urlencode()exists as well for encoding URL parameters.

您需要使用urldecode()来解码它。 urlencode()也用于编码 URL 参数。