Jump to content

Recommended Posts

Hello dear friends,

 

I've an idea so let us say we have paragraph with bad words  ;D

 

$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

 

:shrug:

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  :confused:

 

thank you

 

 

Link to comment
https://forums.phpfreaks.com/topic/230871-bad-words/
Share on other sites

$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  :o

Link to comment
https://forums.phpfreaks.com/topic/230871-bad-words/#findComment-1188474
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/230871-bad-words/#findComment-1188478
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/230871-bad-words/#findComment-1188479
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/230871-bad-words/#findComment-1188552
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.