oracle259 Posted October 11, 2006 Share Posted October 11, 2006 Hi i got this code from the freaks tutorial section. How can i modify it so that it gets the obsenities from a mysql database without losing the ability to filter ie *** multiple curse words in a single input eg buttsagass should give ****sag***[code]<?php function language_filter($string) { $obscenities = @file("path/to/your/file/foul_language.txt"); foreach ($obscenities as $curse_word) { if (stristr(trim($string),$curse_word)) { $length = strlen($curse_word); for ($i = 1; $i <= $length; $i++) { $stars .= "*"; } $string = eregi_replace($curse_word,$stars,trim($string)); $stars = ""; } } return $string; } ?> [/code] Quote Link to comment Share on other sites More sharing options...
JayBachatero Posted October 12, 2006 Share Posted October 12, 2006 You can try this. Need to set the database info.[code]<?php function language_filter($string){ // Connect to the database $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) die("Could not connect to the database\n" . mysql_error()); // Select the database $db_selected = mysql_select_db('database_name', $link); if (!$db_selected) die("Can't select database\n" mysql_error()); // Select the words to filter $request = mysql_query("SELECT colName FROM tblName"); // Define $obscenities and loop through the results and assign it to $obscenities $obscenities = array(); while ($row = mysql_fetch_assoc($request)) $obscenities[] = $row['colName']; // Free result abd close the connection mysql_free_result($request); mysql_close($link); foreach ($obscenities as $curse_word) { if (stristr(trim($string),$curse_word)) { $length = strlen($curse_word); $stars = ''; for ($i = 1; $i <= $length; $i++) $stars .= '*'; $string = eregi_replace($curse_word, $stars, trim($string)); $stars = ''; } } return $string;} ?>[/code] Quote Link to comment Share on other sites More sharing options...
oracle259 Posted October 12, 2006 Author Share Posted October 12, 2006 Something went wrong it does retrieve the info from the mysql database but it only replaces one curse word eg. assmanbutt should return ***man**** but it only returns assman**** do u have any ideas on how to fix this problem Quote Link to comment Share on other sites More sharing options...
JayBachatero Posted October 12, 2006 Share Posted October 12, 2006 I just tested it locally and it worked. Check to see that you actually have that word in the database. Quote Link to comment Share on other sites More sharing options...
oracle259 Posted October 12, 2006 Author Share Posted October 12, 2006 thanks i finally got it to work the way i want it to but i still have one more problem. How can i save the name of each curse_word replaced with *** in an array. Quote Link to comment Share on other sites More sharing options...
JayBachatero Posted October 12, 2006 Share Posted October 12, 2006 You want to log each of the curse word? Quote Link to comment Share on other sites More sharing options...
oracle259 Posted October 13, 2006 Author Share Posted October 13, 2006 Yes, basically Quote Link to comment 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.