PHP - Badwordfilter

Filter für schmutzige Kommentare zum Beispiel in Gästebüchern.


<?php

// Badwordfilter
$badwords = array(
 
"Wort1", "Wort2", "Wort3", "Wort4", "Wort5", "Wort6", "Wort7", "Wort8", "Wort9", "Wort10", 
 
"Wort11","Wort12", "Wort13", "Wort14", "Wort15", "Wort16", "Wort17", "Wort18", "Wort19", 
 
"Wort20"
  
);

function 
badwords($text) {
 global 
$badwords;
 foreach (
$badwords as $b) {
  
$r = $b[0].str_repeat("*", strlen($b)-2).$b[strlen($b)-1];
  if (
function_exists("str_ireplace")) {
   
$text = str_ireplace($b, $r, $text);
  }
  else {
   
$text = str_replace($b, $r, $text);
   }
 }
 return 
$text;
}
?>

Aufruf der Funktion mit:

<?php
 $Kommentar = badwords($Kommentar);
?>

Beispiel eines gefilterten Wortes: W***1

Bausteine

Eine zufällige Auswahl von „Bausteinen” (Snippets) aus den Bereichen CSS, PHP, JavaScript und MySQL.

CSS - Animationen mit Keyframes

PHP - Koordinaten einer Grafik anzeigen

JavaScript - Markierten Text in ein Eingabefeld einfügen

MySQL - Den nächsten und vorherigen Datensatz ermitteln