【发布时间】:2011-11-04 16:09:24
【问题描述】:
我有一个表单,用户可以在其中输入任何 HTML。
var title = "Cool <a href="http://google.com">Check This</a>"
如您所见,变量有",但也可以是'。如果存在",则会导致错误。有什么更好的方法来解决这个问题?像下面这样在数据库中存储转义字符串?
$title = str_replace('"', "'", $_REQUEST['title']); // Replace double quote with single quote as js variable above is wrapped with double quotes.
或者在页面显示之前转义它?像 escape 这样的 jQuery 中的任何东西都可以在这里提供帮助吗?
【问题讨论】:
-
@Alex:错了。如果您有类似
<span title="This link leads to awesome stuff."></span>的内容,它将转换为<span title=This link leads to awesome stuff></span>。结果,只有This会出现在文字上。
标签: javascript jquery escaping quotes