[英]PHP - Show special characters
允许用户输入的代码段
//fetch user input and pass it in URL
alertify.prompt("Please enter note/remarks for this Form (optional):", function (e,value) {
if (e) {
alertify.success("Form has been submitted");
$.post(SITE_URL+"someController/someAction",$("#frm_submit").serialize()+ "&user_id="+user_id+"&comment="+value, function( data ) {
});
}else{
alertify.error("Your Form is not submitted");
}
});
用户输入: 每个Google员工的我的项目Google研发
发布表单后,输入内容不完整,如下所示
echo $_POST['comment']
打印“ 我的项目” Google R
在这里,如果用户输入特殊字符(如&
作为注释,则会中断输入
尝试使用htmlentities($_POST['comment'])
和htmlspecialchars($_POST['comment'], ENT_QUOTES, 'UTF-8')
但无法正常工作。
如何允许用户输入特殊字符?
PS:我没有在数据库中保存此值
正如Daan所建议的那样, &
打破了javascript中的URL。 请找到对我有用的更新代码段
//fetch user input and pass it in URL
alertify.prompt("Please enter note/remarks for this Form (optional):", function (e,value) {
if (e) {
alertify.success("Form has been submitted");
//encodes special characters in user comment
var comment = encodeURIComponent(value);
$.post(SITE_URL+"someController/someAction",$("#frm_submit").serialize()+ "&user_id="+user_id+"&comment="+comment, function( data ) {
});
}else{
alertify.error("Your Form is not submitted");
}
});
使用post参数发送数据。
$.ajax({
type: "POST",
url: your_url,
data: { user_id: user_id, comment: value }
});
尝试这个:
stripslashes($_POST['comment'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.