Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [wolontariat][PHP] Skrypt cenzury słów, (niewielka modyfikacja)
specialboy
post
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 25.09.2005

Ostrzeżenie: (0%)
-----


Witam

Prezentowany skrypt filtruje słowa ale czy jest możliwość go nieco zmodyfikowania po to ze jak wykryje jakieś niewłaściwe słowo, komentarz w ogóle nie zostanie dodany i będzie widnieć napis że: "użyto niewłaściwe wyrazy (czy coś w tym stylu)" i wysłania wiadomość w ogóle się nie pojawi...

Modyfikowany skrypt:
  1. <?php
  2.  
  3. function censor($content){
  4.    $words_list=@file('swearwords.txt');
  5.    $search=array('a','b','i','l','o','p','s');
  6.    $replace=array('(?:a|@|*)','(?:b|8|3|*)','(?:i|1|l|!|*)','(?:l|1|i|!|*)','(?(IMG:http://forum.php.pl/style_emoticons/default/ohmy.gif) |0|*)','(?(IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) |?|*)','(?:s|$|*)');
  7.    foreach($words_list as $badword){
  8.        $badword=rtrim($badword);
  9.        
  10.        $len=strlen($badword);
  11.    if($len <= 0) continue;
  12.        $rep='';
  13.        for($i=0; $i < $len; $i++) break; {
  14.            $rep.='*****';
  15.        }
  16.        
  17.        // Check to see if this word has brackets around it. If it is bracked, censor it in a simple form.
  18.        if (substr($badword, 0, 1) == "[" && substr($badword, ($len - 1), 1) == "]") {
  19.            $content = preg_replace("@".substr($badword, 1, ($len - 2))."@i", substr($rep, 0, (strlen($rep) - 2)), $content);
  20.            continue;
  21.        }
  22.        
  23.        $badwordpreg=preg_split('//', $badword, -1, PREG_SPLIT_NO_EMPTY);
  24.        $badwordpreg=str_replace($search, $replace, $badwordpreg);
  25.        $badword='';
  26.        for($i=0; $i < count($badwordpreg); $i++){
  27.            $badword.=$badwordpreg[$i];
  28.            if($i != (count($badwordpreg)-1)) $badword.='(.{0,5})';
  29.        }
  30.        $badword="/$badword/i";
  31.        $content=preg_replace($badword, $rep, $content);
  32.    }
  33.    return $content;
  34. }
  35.  
  36.  
  37.  
  38. $name = htmlspecialchars($_GET['flot1']);
  39. $message = htmlspecialchars($_GET['flot2']);
  40. if ($message != '')
  41. {
  42.  $name = censor($name);
  43.  $message = censor($message);
  44.  $message = str_replace ("\n","<br>",$message);
  45.  $message = strip_tags ($message, '<br>');
  46.  
  47.  
  48.  $newRow = '<div class="shoutbox"><b>'. strip_tags ($name) . '</b><br><font class="TextSmallDesc">' . date('d.m.Y  H:i') . '</font><br>' . ($message) . '</div><br>';
  49.            
  50.  $oldRows = join ('', file ('shoutbox_wpisy.txt') );
  51.  $fileName = fopen ('shoutbox_wpisy.txt', 'w');
  52.  fputs ($fileName, $newRow . chr(13) . chr(10) . $oldRows);
  53.  fclose ($fileName);
  54. }
  55.  
  56.  
  57.  
  58. header("Location: main.php?dzial=1#KOMENTUJ");
  59.  
  60.  
  61. ?>


Dziękuje i pozdrawiam...
Powód edycji: dodałem tag (cysiaczek)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
ayeo
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 202
Pomógł: 117
Dołączył: 13.04.2007
Skąd: 127.0.0.1

Ostrzeżenie: (0%)
-----


Możliwość jest. Przenoszę na Poszukuję i dodaję stosowny tag!
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 23:30