PHP:简单形式编码/解码
可能这个问题以前已经被问过,不过,我会再问一次。
目前,我面临表单编码的问题。发布我的表单时,所有空格都被“+”字符替换。我想用真正的空格替换这个“+”字符。
有人有 PHP 解决方案吗?
提前致谢。
干杯,伦纳特
Probably, this question has been asked before, though, I'll ask it again.
Currently, I'm facing a problem with form encoding. When posting my form, all spaces are replaced by the "+" character. I would like to replace this "+" character by a real space.
Does someone has a PHP solution for this?
Thanks in advance.
Cheers, Lennart
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
无法复制
根本 任何空格。我做错了什么?
Can't reproduce
no spaces at all. What i m doing wrong?
如果浏览器运行正常,这种情况就不会发生。我的假设是 JavaScript 弄乱了你的数据。在编码 url 时用加号替换空格,也许这会有所帮助。
您可以使用 firebug 检查是否有任何 js 干扰。
This shouldn't happen if the browser behaves correctly. My assumption would be that a javascript is messing with your data. Replacing spaces with pluses is done when encoding urls, maybe that will help.
You can use firebug to check for any js interference.
然后让我们看看代码。
可能您正在做一些事情,例如尝试在另一个组件对数据进行表单编码之前手动对数据进行表单编码。用
+
替换空格是相当标准的,并且是表单编码所期望的,但是如果您不小心做了两次,那么您将在代码处留下编码的+
结束了。如果您正在使用 JavaScript
escape
函数:请勿使用。 (当您需要对表单值进行 URL 编码以包含在参数中时,正确的方法是encodeURIComponent
。escape
是一种其自身的果味非标准编码,您可以使用几乎永远不需要使用。)Then let's see the code.
Possibly you're doing something like trying to form-encode your data manually before another component also form-encodes it. Replacing a space with
+
is quite standard and expected for form-encoding, but if you accidentally do it twice then you're going to be left with an encoded+
at the end of it.If you are using the JavaScript
escape
function: don't. (When you need to URL-encode a form value for inclusion in a parameter, the proper method isencodeURIComponent
.escape
is a fruity non-standard encoding of its own which you should almost never have any need to use.)