Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 22nd, 2010 | Syntax: None | Size: 0.75 KB | Hits: 93 | Expires: Never
Copy text to clipboard
  1. function WordFilter($string = "")
  2.         {
  3.                 // Run a mysql query to grab our words
  4.                 $filter_query_string = "SELECT * FROM forumfilter_fil";
  5.                 $filter_query = mysql_query($filter_query_string, Core::$dbConn);
  6.                
  7.                 // Loop the query and run replacements on the main string
  8.                 while ($row = mysql_fetch_assoc($filter_query))
  9.                 {
  10.                         preg_match("/".$row['word_fil']."/i", $string, $matches);
  11.                        
  12.                         if (isset($matches['0']))
  13.                         {
  14.                                 // Get string length
  15.                                 $word_length = strlen($matches['0']);
  16.                                 $stars = "";
  17.                                
  18.                                 // Loop for *'s
  19.                                 for($i = 0; $i < $word_length; $i++)
  20.                                 {
  21.                                         $stars .= "*";
  22.                                 }
  23.                                
  24.                                 $string = preg_replace("/".$row['word_fil']."/i", $stars, $string);
  25.                         }
  26.                        
  27.                 }
  28.                
  29.                 // Return our new string
  30.                 return $string;
  31.         }