为什么PHP自动html解码我的POST?

为什么PHP自动html解码我的POST?

问题描述:

I'm using Zend Framework for a project. Why when I make POST request and get the params in my controller by $this->_request->getParams() it shows undecoded values? For example a string like Speakers & keyboards in my HTML form is retrieved as Speakers & keyboards from getParams() within PHP.

Doesn't PHP autodecode every posted value?

我正在使用Zend Framework进行项目。 为什么当我通过 $ this-> _request-> getParams() code>发出POST请求并在我的控制器中获取参数时,它显示未解码的值? 例如,像 Speakers& 我的HTML表单中的键盘 code>被检索为 Speakers& amp; 来自PHP中的getParams()的键盘 code>。 p>

PHP不会对每个发布的值进行自动编码吗? p> div>

Hi John, thanks for the hint! I think that's the problem really as I'm making an AJAX POST request and it takes data from the page HTML. So I better use something like urlDecode() before sending the request... What do you think?

The problem then, is that you are sending HTML and you want text.

When you grab the content from the page, get text instead of HTML. So don't use innerHTML or jQuery's .html(). Get a textNode and read its data property, or use jQuery's .text().

Because there is no reason to do so.

Data is encoded for transport, and then decoded again. HTML isn't an encoding used for transport.

The only reason to expect to receive HTML is if HTML was sent, and if HTML is sent then (presumably) HTML is desired. Converting to text wouldn't often be a desired thing to happen next.

PHP autodecodes the escaped content, not content which is in HTML entities.