dk4210 Posted April 15, 2011 Share Posted April 15, 2011 Please take a look at my code here. It currently works, but I think there has to be a better way. Here is the process 1. query the db for the list of bad words 2. checking all post vars for bad words (Entering them in manually) 3. Created an if statement to check is $var !== $var2 There's got to be a better way to code this. If I have say 60 post vars it going to be very time consuming.. Any help will be appreciated. $search_for_bad_words = mysql_query("SELECT * FROM badwords WHERE 1"); // Checking every post var for bad words $ad_title2 = $ad_title; $ad_body2 = $description; $subn2 = $subn; $price2 = $price; $viewname2 = $viewname; $display_name2 = $display_name; $email2 = $email; //$wordlist = "****:cr*p|dang:d*ng|shoot:sh**t"; $seperate_text = "|"; $entry_seperate_text = ":"; while($row = mysql_fetch_array($search_for_bad_words)) { $wordlist = $wordlist.$seperate_text.$row[word].$entry_seperate_text.$row[r_word]; } $words = explode('|', $wordlist); foreach ($words as $word) { list($match, $replacement) = explode(':', $word); $ad_title2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $ad_title2); $ad_body2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $ad_body2); $subn2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $subn2); $price2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $price2); $viewname2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $viewname2); $display_name2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $display_name2); $email2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $email2); } // Checking to see if user used a bad word and is going to get an email and // set a warning in the db if ($ad_title!==$ad_title2 || $description!==$ad_body2 || $subn!==$subn2 || $price!==$price2 || $viewname!==$viewname2 || $display_name!==$display_name2 || $email!==$email2) { $warning = "1"; // Function sends error message send_Warning(); // Function sets number of warnings in database warning_Updatedb($warning,$member_id); } // Function to make sure that user cannot place any more ads if he/she is banned user_Ban($member_id); Quote Link to comment https://forums.phpfreaks.com/topic/233822-a-better-way-to-code-this/ Share on other sites More sharing options...
Muddy_Funster Posted April 15, 2011 Share Posted April 15, 2011 any reason you are using functions for other things and not using one for your bad word checking? Quote Link to comment https://forums.phpfreaks.com/topic/233822-a-better-way-to-code-this/#findComment-1202056 Share on other sites More sharing options...
dk4210 Posted April 15, 2011 Author Share Posted April 15, 2011 Not really no.. That would also be a good practice Quote Link to comment https://forums.phpfreaks.com/topic/233822-a-better-way-to-code-this/#findComment-1202063 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.