I have a site written in PHP that allows users to enter info into a form and upload an image. This information gets written to a MYSQL database. My question is how can I filter out dirty words and or pictures from being uploaded into my database ? Is there any simple way to handle this?
Filtering out Bad Data
Collapse
X
-
Hi,
The images are going to have to be checked manually. (by yourself or a moderator), and the words can be filtered in a number of ways....
try this one
and then check this article...Code:<?php $swears = array("swear","bad","naughty"); $strMessage = str_replace($swears, "***", $strMessage); ?>
http://uk.php.net/str_replace -
If you want multiple replacements:
[php]
<?php
function filterContents( $_str)
{
$_badWords = array("badword1 ", "badword2", "badword3", "badword4") ;
$_replace = array("****", "Removed", "OOPS!", "No can do!");
for($_i = 0; $_i < count($_badWord s); ++$_i)
{
$_randKey = (rand()%count($ _replace)); // random key
$_str = eregi_replace($ _badWords[$_i], $_replace[$_randKey], $_str); //replace with a random replacement.
}
return $_str; //return.
}
$_content = "string here.. maybe some submitted comment.. badword1 badword2 badword3..";
echo filterContents( $_content);
?>
[/php]Comment
Comment