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 Alle Anzeigen
Eine zufällige Auswahl von Codeschnipseln
aus den Bereichen
HTML, CSS,
PHP, JavaScript und
MySQL.
<details> Details
CSS - Ladeanimation ohne Bild-Grafik
PHP - Tage zwischen zwei Datumsangaben berechnen