BAD Word Filter with PHP

July 28th, 2008 by dr.emi

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 !

Translate

Download Unavailable Demo Unavailable
Bookmark Subscribe
Hello my fox! Glad to see you today!

If you love my tutorial, please chose any action from the left button.
No comments yet.
Hi.. ! Wanna say anything about my tutorial ?
Just say it with fill the comment form.
 
 
 
 
 
Category
stack