<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Example of BadWordsFilter class</title>
<style>
body {
background-color: silver;
color: #000;
padding: 6px;
}
h2 {
color: green;
text-decoration: underline;
}
h1 {
text-align: center;
}
.title {
color: blue;
}
.footer {
/*color: grey;*/
text-align: center;
font-weight: bold;
font-size: 1.5em;
padding: 2px;
margin: 2px;
font-family: monospace;
}
</style>
</head>
<body>
<h1>Examples of <span class="title">BadWordsFilter</span> class</h1>
<?php
// include the class file
require('BadWordsFilter.php');
// initialize the class
$filter = new BadWordsFilter();
// examples of isBadWord()
// check if a word is bad or not
echo '<h2>Usage example of isBadWord()</h2>';
if($filter->isBadWord('suck')) {
echo '"suck" is a bad word!<br/>'; // this will be output
} else {
echo '"suck" is not a bad word!<br/>';
}
if($filter->isBadWord('duck')) {
echo '"duck" is a bad word!<br/><br/>';
} else {
echo '"duck" is not a bad word!<br/><br/>'; // this will be output
}
// example of getList()
// get list of all bad words
echo '<h2>Usage example of getList()</h2>';
echo 'Here are all bad words listed bellow:<hr/>';
print_r($filter->getList());
echo '<hr/><br/>';
// examples of getWords() and filterBadWords()
// get words from a sentence xD (string)
echo '<h2>Usage example of getWords() and filterBadWords()</h2>';
$words = $filter->getWords('Well this app sucks');
// print raw array
echo 'Words extracted from "Well this app sucks" (raw):<br/>';
print_r($words);
echo '<br/>Words extracted from "Well this app sucks" and printed with filtering as sentence:<br/>';
// return the same string but with filtered words
echo $filter->filterBadWords($words);
echo '<br/><br/>';
// example of getWordlength()
// get any bad word's character length
echo '<h2>Usage example of getWordlength()</h2>';
echo 'There are '.$filter->getWordlength('suck').' characters in the word "suck"<br/><br/>';
// example of filterBadWord()
// this is the most importannt function of the class
echo '<h2>Usage example of filterBadWord()</h2>';
echo 'The word "suck" turns to "';
if($filter->isBadWord('suck')) {
echo $filter->filterBadWord('suck','?');
} else {
echo 'suck';
}
echo '" after filtering<br/><br/>';
// example of sanitizeWord()
// this is a helper function to get a alphanumeric word (string) from mixed character string
echo '<h2>Usage example of sanitizeWord()</h2>';
echo 'The word "s-u-c-k" turns to "';
print_r($filter->sanitizeWord('s-u-c-k'));
echo '" after sanitizing<br/><br/>';
?>
<strong>Note:</strong> Please look at the source code for more details. Sorry for using bad words for examples. But as the purpose of demonstration I must use those. Otherwise it isn't possible to show a demo how it works. But I hope this class will help your site to maintain a clean environment.<br/><br/>
<div class="footer">Coded by Meraj-Ul Islam<br/>Contact: merajbd7@gmail.com<br/>This file is free to use anywhere you want</div>
</body>
</html>
|