我目前使用jQuery检查textarea的具有HTML在它:(我将继续使用这个)如何使用PHP检查textarea的值是否包含HTML?
if ($('textarea#newMessage').val().match(/<(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/)) {
$('textarea#newMessage').focus();
$('#error').html('Error: HTML is not aloud. Please remove all of the HTML in your message to continue.')
.click(function() { $('#newMessage').focus(); })
.stop(true,true)
.fadeIn(800)
.delay(1500)
.fadeOut(200);
return false;
}
可是,我该如何使用PHP做同样的事情?如果有人禁用了JavaScript,他们可以轻松地在HTML中提交表单。 PHP也有办法做到这一点吗?
见http://stackoverflow.com/questions/5732758/detect-html-tags-in-a-string – Buddy
一个简单的表达是'/ <.*?> /' – Herbert