Created
September 9, 2020 09:43
-
-
Save gaffling/4cb36de0ccbf3fd600fc232bc026d1c2 to your computer and use it in GitHub Desktop.
[Bad Word Filter] Stay away from bad and offensive words #php #class #text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* -------------------------------------------------------------------------- */ | |
/* [Bad Word Filter] Stay away from bad and offensive words #php #class #text */ | |
/* -------------------------------------------------------------------------- */ | |
// the class | |
class BadWordFilter { | |
// variable for storing bad words | |
private $list; | |
// this function will auto initialize the array where all bad words are listed - you can edit/add/remove any elements if necessary | |
function __construct() { | |
$bad_words = array('2 girls 1 cup','2g1c','4r5e','5h1t','5hit','a$$','a$$hole','a_s_s','a2m','a54','a55','a55hole','acrotomophilia','aeolus','ahole','alabama hot pocket','alaskan pipeline','anal','anal impaler','anal leakage','analprobe','anilingus','anus','apeshit','ar5e','areola','areole','arian','arrse','arse','arsehole','aryan','ass','ass fuck','ass fuck','ass hole','assbag','assbandit','assbang','assbanged','assbanger','assbangs','assbite','assclown','asscock','asscracker','asses','assface','assfaces','assfuck','assfucker','ass-fucker','assfukka','assgoblin','assh0le','asshat','ass-hat','asshead','assho1e','asshole','assholes','asshopper','ass-jabber','assjacker','asslick','asslicker','assmaster','assmonkey','assmucus','assmucus','assmunch','assmuncher','assnigger','asspirate','ass-pirate','assshit','assshole','asssucker','asswad','asswhole','asswipe','asswipes','auto erotic','autoerotic','axwound','azazel','azz','b!tch','b00bs','b17ch','b1tch','babeland','baby batter','baby juice','ball gag','ball gravy','ball kicking','ball licking','ball sack','ball sucking','ballbag','balls','ballsack','bampot','bang one\'s box','bangbros','bareback','barely legal','barenaked','barf','bastard','bastardo','bastards','bastinado','batty boy','bawdy','bbw','bdsm','beaner','beaners','beardedclam','beastial','beastiality','beatch','beaver','beaver cleaver','beaver lips','beef curtain','beef curtain','beef curtains','beeyotch','bellend','bender','beotch','bescumber','bestial','bestiality','bi+ch','biatch','big black','big breasts','big knockers','big tits','bigtits','bimbo','bimbos','bint','birdlock','bitch','bitch tit','bitch tit','bitchass','bitched','bitcher','bitchers','bitches','bitchin','bitching','bitchtits','bitchy','black cock','blonde action','blonde on blonde action','bloodclaat','bloody','bloody hell','blow job','blow me','blow mud','blow your load','blowjob','blowjobs','blue waffle','blue waffle','blumpkin','blumpkin','bod','bodily','boink','boiolas','bollock','bollocks','bollok','bollox','bondage','boned','boner','boners','bong','boob','boobies','boobs','booby','booger','bookie','boong','booobs','boooobs','booooobs','booooooobs','bootee','bootie','booty','booty call','booze','boozer','boozy','bosom','bosomy','breasts','Breeder','brotherfucker','brown showers','brunette action','buceta','bugger','bukkake','bull shit','bulldyke','bullet vibe','bullshit','bullshits','bullshitted','bullturds','bum','bum boy','bumblefuck','bumclat','bummer','buncombe','bung','bung hole','bunghole','bunny fucker','bust a load','bust a load','busty','butt','butt fuck','butt fuck','butt plug','buttcheeks','buttfuck','buttfucka','buttfucker','butthole','buttmuch','buttmunch','butt-pirate','buttplug','c.0.c.k','c.o.c.k.','c.u.n.t','c0ck','c-0-c-k','c0cksucker','caca','cacafuego','cahone','camel toe','cameltoe','camgirl','camslut','camwhore','carpet muncher','carpetmuncher','cawk','cervix','chesticle','chi-chi man','chick with a dick','child-fucker','chinc','chincs','chink','chinky','choad','choade','choade','choc ice','chocolate rosebuds','chode','chodes','chota bags','chota bags','cipa','circlejerk','cl1t','cleveland steamer','climax','clit','clit licker','clit licker','clitface','clitfuck','clitoris','clitorus','clits','clitty','clitty litter','clitty litter','clover clamps','clunge','clusterfuck','cnut','cocain','cocaine','coccydynia','cock','c-o-c-k','cock pocket','cock pocket','cock snot','cock snot','cock sucker','cockass','cockbite','cockblock','cockburger','cockeye','cockface','cockfucker','cockhead','cockholster','cockjockey','cockknocker','cockknoker','Cocklump','cockmaster','cockmongler','cockmongruel','cockmonkey','cockmunch','cockmuncher','cocknose','cocknugget','cocks','cockshit','cocksmith','cocksmoke','cocksmoker','cocksniffer','cocksuck','cocksuck','cocksucked','cocksucked','cocksucker','cock-sucker','cocksuckers','cocksucking','cocksucks','cocksucks','cocksuka','cocksukka','cockwaffle','coffin dodger','coital','cok','cokmuncher','coksucka','commie','condom','coochie','coochy','coon','coonnass','coons','cooter','cop some wood','cop some wood','coprolagnia','coprophilia','corksucker','cornhole','cornhole','corp whore','corp whore','corpulent','cox','crabs','crack','cracker','crackwhore','crap','crappy','creampie','cretin','crikey','cripple','crotte','cum','cum chugger','cum chugger','cum dumpster','cum dumpster','cum freak','cum freak','cum guzzler','cum guzzler','cumbubble','cumdump','cumdump','cumdumpster','cumguzzler','cumjockey','cummer','cummin','cumming','cums','cumshot','cumshots','cumslut','cumstain','cumtart','cunilingus','cunillingus','cunnie','cunnilingus','cunny','cunt','c-u-n-t','cunt hair','cunt hair','cuntass','cuntbag','cuntbag','cuntface','cunthole','cunthunter','cuntlick','cuntlick','cuntlicker','cuntlicker','cuntlicking','cuntlicking','cuntrag','cunts','cuntsicle','cuntsicle','cuntslut','cunt-struck','cunt-struck','cus','cut rope','cut rope','cyalis','cyberfuc','cyberfuck','cyberfuck','cyberfucked','cyberfucked','cyberfucker','cyberfuckers','cyberfucking','cyberfucking','d0ng','d0uch3','d0uche','d1ck','d1ld0','d1ldo','dago','dagos','dammit','damn','damned','damnit','darkie','darn','date rape','daterape','dawgie-style','deep throat','deepthroat','deggo','dendrophilia','dick','dick head','dick hole','dick hole','dick shy','dick shy','dickbag','dickbeaters','dickdipper','dickface','dickflipper','dickfuck','dickfucker','dickhead','dickheads','dickhole','dickish','dick-ish','dickjuice','dickmilk','dickmonger','dickripper','dicks','dicksipper','dickslap','dick-sneeze','dicksucker','dicksucking','dicktickler','dickwad','dickweasel','dickweed','dickwhipper','dickwod','dickzipper','diddle','dike','dildo','dildos','diligaf','dillweed','dimwit','dingle','dingleberries','dingleberry','dink','dinks','dipship','dipshit','dirsa','dirty','dirty pillows','dirty sanchez','dirty Sanchez','div','dlck','dog style','dog-fucker','doggie style','doggiestyle','doggie-style','doggin','dogging','doggy style','doggystyle','doggy-style','dolcett','domination','dominatrix','dommes','dong','donkey punch','donkeypunch','donkeyribber','doochbag','doofus','dookie','doosh','dopey','double dong','double penetration','Doublelift','douch3','douche','douchebag','douchebags','douche-fag','douchewaffle','douchey','dp action','drunk','dry hump','duche','dumass','dumb ass','dumbass','dumbasses','Dumbcunt','dumbfuck','dumbshit','dummy','dumshit','dvda','dyke','dykes','eat a dick','eat a dick','eat hair pie','eat hair pie','eat my ass','ecchi','ejaculate','ejaculated','ejaculates','ejaculates','ejaculating','ejaculating','ejaculatings','ejaculation','ejakulate','erect','erection','erotic','erotism','escort','essohbee','eunuch','extacy','extasy','f u c k','f u c k e r','f.u.c.k','f_u_c_k','f4nny','facial','fack','fag','fagbag','fagfucker','fagg','fagged','fagging','faggit','faggitt','faggot','faggotcock','faggots','faggs','fagot','fagots','fags','fagtard','faig','faigt','fanny','fannybandit','fannyflaps','fannyfucker','fanyy','fart','fartknocker','fatass','fcuk','fcuker','fcuking','fecal','feck','fecker','feist','felch','felcher','felching','fellate','fellatio','feltch','feltcher','female squirting','femdom','fenian','fice','figging','fingerbang','fingerfuck','fingerfuck','fingerfucked','fingerfucked','fingerfucker','fingerfucker','fingerfuckers','fingerfucking','fingerfucking','fingerfucks','fingerfucks','fingering','fist fuck','fist fuck','fisted','fistfuck','fistfucked','fistfucked','fistfucker','fistfucker','fistfuckers','fistfuckers','fistfucking','fistfucking','fistfuckings','fistfuckings','fistfucks','fistfucks','fisting','fisty','flamer','flange','flaps','fleshflute','flog the log','flog the log','floozy','foad','foah','fondle','foobar','fook','fooker','foot fetish','footjob','foreskin','freex','frenchify','frigg','frigga','frotting','fubar','fuc','fuck','fuck','f-u-c-k','fuck buttons','fuck hole','fuck hole','Fuck off','fuck puppet','fuck puppet','fuck trophy','fuck trophy','fuck yo mama','fuck yo mama','fuck you','fucka','fuckass','fuck-ass','fuck-ass','fuckbag','fuck-bitch','fuck-bitch','fuckboy','fuckbrain','fuckbutt','fuckbutter','fucked','fuckedup','fucker','fuckers','fuckersucker','fuckface','fuckhead','fuckheads','fuckhole','fuckin','fucking','fuckings','fuckingshitmotherfucker','fuckme','fuckme','fuckmeat','fuckmeat','fucknugget','fucknut','fucknutt','fuckoff','fucks','fuckstick','fucktard','fuck-tard','fucktards','fucktart','fucktoy','fucktoy','fucktwat','fuckup','fuckwad','fuckwhit','fuckwit','fuckwitt','fudge packer','fudgepacker','fudge-packer','fuk','fuker','fukker','fukkers','fukkin','fuks','fukwhit','fukwit','fuq','futanari','fux','fux0r','fvck','fxck','gae','gai','gang bang','gangbang','gang-bang','gang-bang','gangbanged','gangbangs','ganja','gash','gassy ass','gassy ass','gay','gay sex','gayass','gaybob','gaydo','gayfuck','gayfuckist','gaylord','gays','gaysex','gaytard','gaywad','gender bender','genitals','gey','gfy','ghay','ghey','giant cock','gigolo','ginger','gippo','girl on','girl on top','girls gone wild','git','glans','goatcx','goatse','god','god damn','godamn','godamnit','goddam','god-dam','goddammit','goddamn','goddamned','god-damned','goddamnit','godsdamn','gokkun','golden shower','goldenshower','golliwog','gonad','gonads','goo girl','gooch','goodpoop','gook','gooks','goregasm','gringo','grope','group sex','gspot','g-spot','gtfo','guido','guro','h0m0','h0mo','ham flap','ham flap','hand job','handjob','hard core','hard on','hardcore','hardcoresex','he11','hebe','heeb','hell','hemp','hentai','heroin','herp','herpes','herpy','heshe','he-she','hircismus','hitler','hiv','ho','hoar','hoare','hobag','hoe','hoer','holy shit','hom0','homey','homo','homodumbshit','homoerotic','homoey','honkey','honky','hooch','hookah','hooker','hoor','hootch','hooter','hooters','hore','horniest','horny','hot carl','hot chick','hotsex','how to kill','how to murdep','how to murder','huge fat','hump','humped','humping','hun','hussy','hymen','iap','iberian slap','inbred','incest','injun','intercourse','jack off','jackass','jackasses','jackhole','jackoff','jack-off','jaggi','jagoff','jail bait','jailbait','jap','japs','jelly donut','jerk','jerk off','jerk0ff','jerkass','jerked','jerkoff','jerk-off','jigaboo','jiggaboo','jiggerboo','jism','jiz','jiz','jizm','jizm','jizz','jizzed','jock','juggs','jungle bunny','junglebunny','junkie','junky','kafir','kawk','kike','kikes','kill','kinbaku','kinkster','kinky','klan','knob','knob end','knobbing','knobead','knobed','knobend','knobhead','knobjocky','knobjokey','kock','kondum','kondums','kooch','kooches','kootch','kraut','kum','kummer','kumming','kums','kunilingus','kunja','kunt','kwif','kwif','kyke','l3i+ch','l3itch','labia','lameass','lardass','leather restraint','leather straight jacket','lech','lemon party','LEN','leper','lesbian','lesbians','lesbo','lesbos','lez','lezza/lesbo','lezzie','lmao','lmfao','loin','loins','lolita','looney','lovemaking','lube','lust','lusting','lusty','m0f0','m0fo','m45terbate','ma5terb8','ma5terbate','mafugly','mafugly','make me come','male squirting','mams','masochist','massa','masterb8','masterbat*','masterbat3','masterbate','master-bate','master-bate','masterbating','masterbation','masterbations','masturbate','masturbating','masturbation','maxi','mcfagget','menage a trois','menses','menstruate','menstruation','meth','m-fucking','mick','microphallus','middle finger','midget','milf','minge','minger','missionary position','mof0','mofo','mo-fo','molest','mong','moo moo foo foo','moolie','moron','mothafuck','mothafucka','mothafuckas','mothafuckaz','mothafucked','mothafucked','mothafucker','mothafuckers','mothafuckin','mothafucking','mothafucking','mothafuckings','mothafucks','mother fucker','mother fucker','motherfuck','motherfucka','motherfucked','motherfucker','motherfuckers','motherfuckin','motherfucking','motherfuckings','motherfuckka','motherfucks','mound of venus','mr hands','muff','muff diver','muff puff','muff puff','muffdiver','muffdiving','munging','munter','murder','mutha','muthafecker','muthafuckker','muther','mutherfucker','n1gga','n1gger','naked','nambla','napalm','nappy','nawashi','nazi','nazism','need the dick','need the dick','negro','neonazi','nig nog','nigaboo','nigg3r','nigg4h','nigga','niggah','niggas','niggaz','nigger','niggers','niggle','niglet','nig-nog','nimphomania','nimrod','ninny','ninnyhammer','nipple','nipples','nob','nob jokey','nobhead','nobjocky','nobjokey','nonce','nsfw images','nude','nudity','numbnuts','nut butter','nut butter','nut sack','nutsack','nutter','nympho','nymphomania','octopussy','old bag','omg','omorashi','one cup two girls','one guy one jar','opiate','opium','orally','organ','orgasim','orgasims','orgasm','orgasmic','orgasms','orgies','orgy','ovary','ovum','ovums','p.u.s.s.y.','p0rn','paedophile','paki','panooch','pansy','pantie','panties','panty','pawn','pcp','pecker','peckerhead','pedo','pedobear','pedophile','pedophilia','pedophiliac','pee','peepee','pegging','penetrate','penetration','penial','penile','penis','penisbanger','penisfucker','penispuffer','perversion','phallic','phone sex','phonesex','phuck','phuk','phuked','phuking','phukked','phukking','phuks','phuq','piece of shit','pigfucker','pikey','pillowbiter','pimp','pimpis','pinko','piss','piss off','piss pig','pissed','pissed off','pisser','pissers','pisses','pisses','pissflaps','pissin','pissin','pissing','pissoff','pissoff','piss-off','pisspig','playboy','pleasure chest','pms','polack','pole smoker','polesmoker','pollock','ponyplay','poof','poon','poonani','poonany','poontang','poop','poop chute','poopchute','Poopuncher','porch monkey','porchmonkey','porn','porno','pornography','pornos','pot','potty','prick','pricks','prickteaser','prig','prince albert piercing','prod','pron','prostitute','prude','psycho','pthc','pube','pubes','pubic','pubis','punani','punanny','punany','punkass','punky','punta','puss','pusse','pussi','pussies','pussy','pussy fart','pussy fart','pussy palace','pussy palace','pussylicking','pussypounder','pussys','pust','puto','queaf','queaf','queef','queer','queerbait','queerhole','queero','queers','quicky','quim','racy','raghead','raging boner','rape','raped','raper','rapey','raping','rapist','raunch','rectal','rectum','rectus','reefer','reetard','reich','renob','retard','retarded','reverse cowgirl','revue','rimjaw','rimjob','rimming','ritard','rosy palm','rosy palm and her 5 sisters','rtard','r-tard','rubbish','rum','rump','rumprammer','ruski','rusty trombone','s hit','s&m','s.h.i.t.','s.o.b.','s_h_i_t','s0b','sadism','sadist','sambo','sand nigger','sandbar','sandbar','Sandler','sandnigger','sanger','santorum','sausage queen','sausage queen','scag','scantily','scat','schizo','schlong','scissoring','screw','screwed','screwing','scroat','scrog','scrot','scrote','scrotum','scrud','scum','seaman','seamen','seduce','seks','semen','sex','sexo','sexual','sexy','sh!+','sh!t','sh1t','s-h-1-t','shag','shagger','shaggin','shagging','shamedame','shaved beaver','shaved pussy','shemale','shi+','shibari','shirt lifter','shit','s-h-i-t','shit ass','shit fucker','shit fucker','shitass','shitbag','shitbagger','shitblimp','shitbrains','shitbreath','shitcanned','shitcunt','shitdick','shite','shiteater','shited','shitey','shitface','shitfaced','shitfuck','shitfull','shithead','shitheads','shithole','shithouse','shiting','shitings','shits','shitspitter','shitstain','shitt','shitted','shitter','shitters','shitters','shittier','shittiest','shitting','shittings','shitty','shiz','shiznit','shota','shrimping','sissy','skag','skank','skeet','skullfuck','slag','slanteye','slave','sleaze','sleazy','slope','slope','slut','slut bucket','slut bucket','slutbag','slutdumper','slutkiss','sluts','smartass','smartasses','smeg','smegma','smut','smutty','snatch','sniper','snowballing','snuff','s-o-b','sod off','sodom','sodomize','sodomy','son of a bitch','son of a motherless goat','son of a whore','son-of-a-bitch','souse','soused','spac','spade','sperm','spic','spick','spik','spiks','splooge','splooge moose','spooge','spook','spread legs','spunk','stfu','stiffy','stoned','strap on','strapon','strappado','strip','strip club','stroke','stupid','style doggy','suck','suckass','sucked','sucking','sucks','suicide girls','sultry women','sumofabiatch','swastika','swinger','t1t','t1tt1e5','t1tties','taff','taig','tainted love','taking the piss','tampon','tard','tart','taste my','tawdry','tea bagging','teabagging','teat','teets','teez','teste','testee','testes','testical','testicle','testis','threesome','throating','thrust','thug','thundercunt','tied up','tight white','tinkle','tit','tit wank','tit wank','titfuck','titi','tities','tits','titt','tittie5','tittiefucker','titties','titty','tittyfuck','tittyfucker','tittywank','titwank','toke','tongue in a','toots','topless','tosser','towelhead','tramp','tranny','transsexual','trashy','tribadism','trumped','tub girl','tubgirl','turd','tush','tushy','tw4t','twat','twathead','twatlips','twats','twatty','twatwaffle','twink','twinkie','two fingers','two fingers with tongue','two girls one cup','twunt','twunter','ugly','unclefucker','undies','undressing','unwed','upskirt','urethra play','urinal','urine','urophilia','uterus','uzi','v14gra','v1gra','vag','vagina','vajayjay','va-j-j','valium','venus mound','veqtable','viagra','vibrator','violet wand','virgin','vixen','vjayjay','vodka','vomit','vorarephilia','voyeur','vulgar','vulva','w00se','wad','wang','wank','wanker','wankjob','wanky','wazoo','wedgie','weed','weenie','weewee','weiner','weirdo','wench','wet dream','wetback','wh0re','wh0reface','white power','whiz','whoar','whoralicious','whore','whorealicious','whorebag','whored','whoreface','whorehopper','whorehouse','whores','whoring','wigger','willies','willy','window licker','wiseass','wiseasses','wog','womb','wop','wrapping men','wrinkled starfish','wtf','xrated','x-rated','xx','xxx','yaoi','yeasty','yellow showers','yid','yiffy','yobbo','zibbi','zoophilia','zubb'); | |
$this->list = $bad_words; // store bad words array to the variable for later usage | |
} | |
// this function will determine if given word (string) is a bad word or not and will return boolean | |
function isBadWord($word) { | |
if (in_array(strtolower($word),$this->list)) return true; // given $word is a bad word | |
else return false; | |
} | |
// this function will return the bad words list as an array upon call | |
function getList() { | |
return $this->list; | |
} | |
// this is an auxiliary function which extracts words from string - usefull for extracting words from user inputs e.g. user comments | |
function getWords($string) { | |
return preg_split('/\s+/', $string); // breaks string and returns words from strings - extra whitespaces are ignored | |
} | |
// function to get any bad word's length - useful when you want to do some custom filtering | |
function getWordlength($word) { | |
if ($this->isBadWord($word)) return strlen($word); | |
else return 0; // returns 0 if the given string isn't a bad word | |
} | |
// this function replace bad word's chracters with other characters. asterisk (*) icon is the default. | |
// pass your desired character in second parameter - replaced characters will be in exact length of given string's length | |
function filterBadWord($word, $delimiter='') { | |
if (!empty($delimiter) && strlen($delimiter)!=1) $delimiter = ''; // if the delimiter character is not a single character | |
if ($this->isBadWord($word)) { | |
if (empty($delimiter)) $delimiter = '*'; | |
$replace = ''; | |
for ($i=0; $i < $this->getWordlength($word); $i++) | |
$replace .= $delimiter; | |
return str_replace($word, $replace, $word); | |
} | |
} | |
// this function replace bad word from array - pass your desired character in second parameter | |
// replaced characters will be in exact length of given string's length | |
function filterBadWords($words, $delimiter='') { | |
if (!is_array($words)) return false; // the words must be passed as array | |
else { | |
if (!empty($delimiter) && strlen($delimiter)!=1) $delimiter = ''; // if the desired character is not a single character | |
$string = ''; | |
foreach ($words as $word) { | |
if (!$this->isBadWord($word)) | |
$string .= $word.' '; | |
else { | |
if (empty($delimiter)) $delimiter = '*'; | |
$replace = ''; | |
for ($i=0; $i < $this->getWordlength($word); $i++) | |
$replace .= $delimiter; | |
$string .= str_replace($word,$replace,$word); | |
} | |
} | |
return trim($string); | |
} | |
} | |
// this function will return an alphanumeric string from given string - helpul when you want to trim a word | |
function sanitizeWord($word) { | |
return preg_replace("/[^a-zA-Z0-9]+/", '', $word); | |
} | |
} | |
// initialize the class | |
$filter = new BadWordFilter(); | |
?> | |
<!DOCTYPE html> | |
<html lang="en-US"> | |
<head> | |
<meta charset="utf-8"/> | |
<title>BadWordFilter Class</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"/> | |
<style> | |
body { font-family: Arial; color: black; background-color: white; padding: 33px 33%; } | |
h1 { font-family: Verdana; color: navy; } | |
h2 { text-decoration: bold; color: crimson; } | |
small { font-family: monospace;color: grey; font-size: 1.5em; margin-top: 33px; } | |
</style> | |
</head> | |
<body> | |
<h1>BadWordFilter Class</h1> | |
<?php | |
// examples of isBadWord() - check if a word is bad or not | |
echo '<h2>Usage example of isBadWord("suck") and isBadWord("duck")</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:<br><textarea style="width:80%;height:250px;">'; | |
print_r($filter->getList()); | |
echo '</textarea><br>'; | |
// examples of getWords() and filterBadWords() - get words from a sentence (string) | |
echo '<h2>Usage example of getWords("Well this script sucks") and filterBadWords(getWords("Well this script sucks"))</h2>'; | |
$words = $filter->getWords('Well this script sucks'); | |
// print raw array | |
echo 'Words extracted from "Well this script sucks" (raw):<br>'; | |
print_r($words); | |
echo '<br><br>Words extracted from "Well this script 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 important function of the class | |
echo '<h2>Usage example of filterBadWord("suck","?")</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("s-u-c-k")</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> <br> | |
Excuse me for using bad words for the example, <br> | |
but for the purpose of demonstration I unfortunately have to do so. <br> | |
<br> | |
<small>code by adilbo</small> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment