我有两个问题
- 当我提交角色
'
时通过我的 HTML 表单(使用 POST)就可以了。但是,在表单中,我允许修改提交的内容,当它被引入时,'
之后的任何内容。消失。我推断这是因为当我分配包含'
的文本内容时到文本字段,它会关闭引用。例如,如果我在那里提交“Hello,我是 John”,则会执行:<input type=text value='Hello there I'm Jon />
所以你看,I'm
中的撇号关闭 value 属性的引用。因此,我能想到的唯一解决方案是转义撇号,但即使我将 mysql_real_escape_string() 函数留在内容上(因为它被提交到数据库,并为此表单进行转义和检索)。 - 同样,当我提交
&
时或+
,它消失了。每当我尝试在任何地方打印它时,无论使用htmlspecialchars()
,都会发生这种情况。函数(我的印象是应该将这些字符编码为 HTML 格式,例如:&
)。举个例子,如果有人输入Me & you
那么它将显示为Me you
.
所以我问:如何解决上述问题,似乎与特殊字符有关,尽管它们已经转义了(我什至尝试再次应用转义函数)?如果我应该提供任何示例代码,请告诉我,但我已经解释了我对每个输入所做的事情。
最佳答案
When I submit the character
'
through my HTML form (using POST) it is fine. However, in the form I allow to modify the submitted content, when it is brought in, anything after the ' disappears. I've deduced that this is because when I assign the text content containing the ' to the text field, it closes the quote. For example, if I submit Hello there I'm John, it will do:<input type=text value='Hello there I'm Jon />
So you see, the apostrophe in I'm closes the quote for the value attribute. So the only solution I can think of would be to escape the apostrophe, but even when I leave mymysql_real_escape_string()
function on the content (as it's submitted to a database escaped and retrieved for this form).
这与提交数据无关。您正在尝试使用'
在以 '
分隔的属性值中字符。
使用 htmlspecialchars($data, ENT_QUOTES)
Similarly, when I submit an & or a +, it disappears. This happens any time I try to print it anywhere, regardless of using the htmlspecialchars() function (which I was under the impression should encode them in HTML format for such characters, like: &). so as an example, if someone enters Me & you then it will be displayed as Me you.
在编码为 application/x-www-form-urlencoded &
的数据中表示“新键=值对的开始”和 +
意思是“一个空间”。您需要 urlencode($data)
.
关于php - 通过 POST 提交时删除某些字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9501359/