BAD Word Filter with PHP

bad word mang nyEbelin kalo di komen2 ada karakter2 berbahaya kaya petik dua petik satu dan slash.
Sebenernye kalo nyang pernah gw baca di forum phpbuilder.com
dengan menggunakan strip tags aja dah aman, tapi ada baikna kalo security form di lipatgandakan. mudah2an si berguna walopun fungsi bwatan gw ni cuma beberapa baris

 

Code:

function wordFilter($strToFilter)
{
$strToFilter = str_replace("'", "", $strToFilter);
$strToFilter = str_replace("  ", " ", $strToFilter);
$strToFilter = str_replace('"', "", $strToFilter);
$strToFilter = str_replace("|", "", $strToFilter);
$strToFilter = str_replace("\'", "", $strToFilter);
$strToFilter = str_replace("\"", "", $strToFilter);
$strToFilter = str_replace("\\", "", $strToFilter);
$strToFilter = str_replace("/", "", $strToFilter);
return $strToFilter;
}

contoh penggunaan:
Code:

echo 'String lu: ';
echo $str = "Thank\"s   'Brother' !";
echo '<BR> Dengan Filter akan menjadi: ';
echo wordFilter($str); //hasilna: Thanks Brother !

Leave a Reply

Your email address will not be published. Required fields are marked *