Jump to content

A better way to code this


dk4210

Recommended Posts

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);  


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.