Php 坏词过滤器,如何与URL结合替换

Php 坏词过滤器,如何与URL结合替换,php,jquery,filter,replace,word,Php,Jquery,Filter,Replace,Word,我有两个脚本——javascript和php 这将清除url <script type="text/javascript"> $(document).ready(function() { $('.search-form').submit(function() { window.location.href = "/file_"+ $('.search-form input:text').val() + ".html"; return false

我有两个脚本——javascript和php

这将清除url

    <script type="text/javascript">
$(document).ready(function() {
    $('.search-form').submit(function() {
        window.location.href = "/file_"+ $('.search-form input:text').val() + ".html";
     return false;
    });
});
</script>

$(文档).ready(函数(){
$('.search form').submit(函数(){
window.location.href=“/file_389;”+$('.search表单输入:text').val()+“.html”;
返回false;
});
});
这是坏字过滤器

<?php
    if (isset($_GET['search']))
    {
    $search=$_GET['search'];

    if(is_array($badwords) && sizeof($badwords) >0)
    {
    foreach($badwords as $theword)
    $search = ereg_replace($theword,"haha",$search);
    }
    $search=preg_replace("/\s+/"," ",$search);

    $keyword = str_replace(" ", "+", $search);
    }

    else
    {
    $keyword = str_replace(" ", "+a", $keyword);
    }
    ?> 


如何将这两个脚本组合起来,用“哈哈”替换url中的坏单词?

您可以在PHP中重定向

首先,形式:

<form action="somefile.php">
<input type="text" id="search" name="search" value="" placeholder="Enter here..." />
<button>Search</button>
</form>
也可以使用ajax检查和清除关键字:

<script type="text/javascript">
$(document).ready(function() {
  $('.search-form').submit(function() {
    $.ajax({ type: "POST", dataType: "HTML",
             url: "clean.php", 
             data: { search: $('.search-form input:text').val()},
             success: function(response){
               if (response.length > 0) {
                 window.location.href = "/" + response;
               }
             }
   });
</script>
有关ajax/post/get(jQuery)的更多信息,请访问:


提醒一句:糟糕的语言过滤器通常是一个坏主意,因为它们经常破坏有效的使用,那些试图绕过它们的人可以简单地转向1337 speak并使用特殊字符来传达信息。只有两个例子:assignment和ashita.org,因为它们都包含频繁标记的单词,所以你会得到类似hahaingment和ahahahaa.org的东西
<script type="text/javascript">
$(document).ready(function() {
  $('.search-form').submit(function() {
    $.ajax({ type: "POST", dataType: "HTML",
             url: "clean.php", 
             data: { search: $('.search-form input:text').val()},
             success: function(response){
               if (response.length > 0) {
                 window.location.href = "/" + response;
               }
             }
   });
</script>
  if (isset($_GET['search'])){
    $search=$_GET['search'];
    if(count($badwords)){
    foreach($badwords as $theword)
      $search = ereg_replace($theword,"haha",$search);
    }
    $search=preg_replace("/\s+/"," ",$search);
    $keyword = str_replace(" ", "+", $search);
  } else {
    $keyword = str_replace(" ", "+a", $keyword);
  }
  // here you can do any checks with the search and redirect to anywhere
  if (strlen($keyword)){
    echo("file_{$keyword}.html");
  } ?>
http://api.jquery.com/jquery.ajax/
http://api.jquery.com/jquery.post/
http://api.jquery.com/jquery.get/