Php 使用服务器端脚本筛选HTML输入元素的内容

Php 使用服务器端脚本筛选HTML输入元素的内容,php,javascript,html,xml,Php,Javascript,Html,Xml,此php脚本删除所有此链接。“; $filter=preg_replace(“/你的意思是 <script type="javascript"> function removeAll(theForm) { var str = theForm.text.value; if (str) theForm.text.value = str.replace(/<a(.*)<\/a>/ig,""); } </script> <form> &l

此php脚本删除所有
此链接。“;
$filter=preg_replace(“/你的意思是

<script type="javascript">
function removeAll(theForm) {
  var str = theForm.text.value;
  if (str) theForm.text.value = str.replace(/<a(.*)<\/a>/ig,"");
}
</script>
<form>
  <textarea name="text" style="width: 400px; height: 100px"></textarea>
  <input type="button" value="Remove all anchors" onclick="removeAll(this.form)" />
</form>

函数removeAll(表单){
var str=form.text.value;

如果(str)theForm.text.value=str.replace(/),看起来您正在尝试使用正则表达式过滤HTML

请不要


看看PHP中的一个全面的HTML过滤机制。使用它,您可以确保用户提交的HTML符合特定的指导原则,例如确保没有锚定标记。

这里不清楚您在问什么。是否希望表单向PHP脚本发送请求,以便您可以剥离
标记并获得结果?令人难以置信的是,有些人对非英语母语人士没有耐心。让艾哈迈德在30分钟内回复,然后你开始向下投票、投票结束等等-现在只有10分钟!!!现在有3条建议他需要看一下,然后他也许可以重新制定问题的答案us@mplungj安,我猜他是因为愚蠢的regex html meme而被否决的受害者。(这有时就像在这里说Jehova。)为了准确性和可查找性,我重新命名了这个问题。我认为标题应该是
使用基于服务器端脚本的客户端脚本过滤html输入元素的内容
<form>
<textarea name="" style="width: 400px; height: 100px"></textarea>
<input type="button" value="Remove all <a></a>" onClick="">
</form>
<script type="javascript">
function removeAll(theForm) {
  var str = theForm.text.value;
  if (str) theForm.text.value = str.replace(/<a(.*)<\/a>/ig,"");
}
</script>
<form>
  <textarea name="text" style="width: 400px; height: 100px"></textarea>
  <input type="button" value="Remove all anchors" onclick="removeAll(this.form)" />
</form>
<script type="javascript">
function validate(theForm) {
  var str = theForm.text.value;
  if (str && str.match(/<a(.*)<\/a>/ig)) {
    alert('Please do not enter any links')
    theForm.text.focus();
    return false;
  }
  return true;
}
</script>
<form method="post" action="" onsubmit="return validate(this)">
  <textarea name="text" style="width: 400px; height: 100px"></textarea>
  <input type="submit" name="submit" value="Send to server" />
</form>