php - Swear Word Filter - output from database -



php - Swear Word Filter - output from database -

i have html form saves name , comment mysql database. name , comment entries displayed in table format on php page.

i want have swear words comment field appear three asterisks when displayed in php outputted table.

i got work follows:

swear.php

<?php $find = array("badword1","badword2","badword3"); //words don't want displayed $replace = array("***","***","***"); //the replacements ?>

process.php

<?php //connect database $dbc = mysqli_connect('host', 'username', 'password', 'db') or die('error connecting mysql server.'); //connect swear.php require("swear filter.php"); //process form & email $name = mysqli_real_escape_string($dbc, trim($_post['name'])); $email = mysqli_real_escape_string($dbc, trim($_post['email'])); $comment= mysqli_real_escape_string($dbc, trim($_post['comment'])); $comment=str_replace($find, $replace, $comment); $from = 'from: whoever'; $to = 'anemail@something.com'; $subject = 'hello'; $human = mysqli_real_escape_string($dbc, $_post['human']); $body = "from: $name\n e-mail: $email\n message:\n $comment"; if(isset($_post['submit'])){ if ($name != '' && $email != '') { if ($human == '4') { if (mail ($to, $subject, $body, $from)) { echo '<h1 class=\"meantime\"></h1>'; } else { echo '<h1 class=\"meantime\">something went wrong, go , seek again!</h1>'; } } else if ($_post['submit'] && $human != '4') { echo '<h1 class=\"incorrect\">you answered anti-spam question incorrectly!</h1>'; } } else { echo '<h1 class=\"required\">you need fill in required fields!!</h1>'; } } ?> <?php //connect database $dbc = mysqli_connect('host', 'username', 'password', 'db') or die('error connecting mysql server.'); //create insert statement $query = "insert table(name, email, comment, date) values ('$name', '$email', '$comment', now())"; //insert record table $result = mysqli_query($dbc, $query) or die ('error querying database.'); //close connection database mysqli_close($dbc); //display give thanks user , link form page print "<br>"; print "<h2 class=\"meantime\">nice 1 <span class=\"nice\"> " . stripslashes($name) . "</span>. shall check out.</h1>"; print "<h3 class=\"meantime\">in meantime, see others have posted.</h3>"; print "<br><br>"; print "<h3 class=\"meantime\"><a href=\"comments.php\"><span class=\"underline\">comments far</span></a></h3>"; print "<br><br>"; ?>

is there more efficient way of completing swear.php file.

do have type three asterisks each replacement badword - since same time?

is there improve way overall of implementing simple swear word filter?

thanks help, andy ;-)

php mysql

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -