我目前使用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