Basic word filter/replace words ::Class::

Information for PHP. Hypertext Preprocessor
Post Reply
Posts: 94
Joined: Sun Mar 01, 2015 4:36 am

Basic word filter/replace words ::Class::

Post by dzcadii » Sun Mar 01, 2015 6:33 pm

Here is a simple script that will replace any defined words in a database.

This script reads the input, checks the database for that word and replaces it with the instructed replacement.

Database set up:
Database table name wordfilter
id int(11) autoincrement primary
word varchar(255)
replace_with varchar(255)

Code: Select all

//$UserInput['comments'] would be the $_POSTED comment from the form

class word_filter{

function word_filter($UserInput){
//Connect to the database

$this->query_string = "SELECT * FROM wordfilter";
$this->query = mysql_query($this->query_string);

$PWords=array();//Post words

foreach($PWords as $key=>$value){


function db_connection(){
//Put your database connection functions and information here
//To include selecting the wordfilter database table
This is how you would call the filter

Code: Select all

$filter = new filter($UserInput);
//Echo out the new result (this includes the changes)
echo $filter->NUserInput;

Post Reply