Sunday, April 03 2016

Predict illegal words from the content in codeigniter

To avoid the illegal words in your content as you are using codeigniter provide word_censor functions.Here we are brief explain about this function. First you mention what are the words are you going to skip from the content. Those values are maintain your table.

Table:

CREATE TABLE `test`.`get_illegal_words` (`word_id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `illegal_word` VARCHAR(255) NOT NULL) ENGINE = InnoDB;

In Codeigniter:

Load helper file for text.
$this->load->helper ('text');                          
Get the illegal words from the table .
$query = $this->settingsmodel->get_illegalwords(1);
if($query)
{
	foreach($query as $row)
	{                                                                         
		$id = $row->id;
		$illwords = $row->illwords;
	}                                                      
}
      
Compare the user input and table
$words=explode(',',$illwords);    
$pagecontent=$this->input->post('pagecontent');                                 
$string = word_censor($pagecontent, $words, 'Beep!');     
$pos = strrpos($string, "Beep!");
if (strstr($string, 'Beep!') !== false)
{
	$this->session->set_flashdata('error',"Dont write illegal words to this post");
	redirect('/settings/replygpost/','refresh');  
}
else
{       
	/* Insert Your Code */
}

Share Your Thoughts

phpexpertise

I’m Blogger and Programming Blog, Tutorials, PHP, MySQL, jQuery, Laravel, Wordpress and Codeigniter