manalnor Posted March 17, 2011 Share Posted March 17, 2011 Hello dear friends, I've an idea so let us say we have paragraph with bad words $para = "Hello shit oh shit what the hell this is shit day"; Now let say we create textarea <textarea id="badword" name="badword"> </textarea> and let us say we have database table as following CREATE TABLE `banned` ( `id` varchar(50) NOT NULL default '', `badwords` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; consider we have connetion and can update mysql table badwords 1- now how we can enter word per line in this textarea example we entered in this textarea per line shit hell die death then by click on submit it stored in an database table 'banned' as INSERT INTO `banned` VALUES ('1', 'shit,hell,die,death'); 2- if we called `badwords` from table 'banned' how then can put 'shit,hell,die,death' into array so we can exclude it from $para can someone please help me in this , how to store textarea per line as sperated words in database table and how then call it back as array to exclude it form our paragraph Or it there any other simple way doing the same thank you Quote Link to comment https://forums.phpfreaks.com/topic/230871-bad-words/ Share on other sites More sharing options...
phpTrainee Posted March 17, 2011 Share Posted March 17, 2011 $message = "Hello shit oh shit what the hell this is shit day"; $badwords = array('shit','hell','die','death'); foreach ($badwords as $badwords) { $message = str_replace($badwords, '', $message); } echo $message; Quote Link to comment https://forums.phpfreaks.com/topic/230871-bad-words/#findComment-1188471 Share on other sites More sharing options...
manalnor Posted March 17, 2011 Author Share Posted March 17, 2011 $message = "Hello shit oh shit what the hell this is shit day"; $badwords = array('shit','hell','die','death'); foreach ($badwords as $badwords) { $message = str_replace($badwords, '', $message); } echo $message; thank you this solve the part 2, Part 1 how to store words where each word per line within textarea to database table Quote Link to comment https://forums.phpfreaks.com/topic/230871-bad-words/#findComment-1188474 Share on other sites More sharing options...
Pikachu2000 Posted March 17, 2011 Share Posted March 17, 2011 You want each word in its own record, right? If that's correct, just explode() the string from the textarea on the comma, and build the INSERT query string from that. pseudo-code $array = explode(',', $_POST['textarea']); foreach( $array as $value ) { $inserts[] = "( '', '" . trim($value) . "' )"; } $query = 'INSERT INTO table (id, word) VALUES ' . implode(', ', $inserts); Quote Link to comment https://forums.phpfreaks.com/topic/230871-bad-words/#findComment-1188478 Share on other sites More sharing options...
phpTrainee Posted March 17, 2011 Share Posted March 17, 2011 You don't need to store the words in the database. Just create a function. Put this piece of code in your php page anywhere BEFORE you get the message. function censor($message) { $badwords = array('shit','hell','die','death'); foreach ($badwords as $badwords) { $message = str_replace($badwords, '', $message); } return $message; } And after you grab the message from wherever, call the function before displaying it. $message = "Hello shit oh shit what the hell this is shit day"; $message = censor($message); echo $message; Quote Link to comment https://forums.phpfreaks.com/topic/230871-bad-words/#findComment-1188479 Share on other sites More sharing options...
QuickOldCar Posted March 17, 2011 Share Posted March 17, 2011 I made a safe filter that the bad words are kept in a text file. Here's the demo and the download is also there. http://get.blogdns.com/dynaindex/Safe-Filter/ You will see it can block either words or entire posts with the dropdown selection. The x can also be whatever like it to be, such as OOPS, replacement of words or w/e you like Quote Link to comment https://forums.phpfreaks.com/topic/230871-bad-words/#findComment-1188552 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.