PHP word block script [Request]

Status
Not open for further replies.

Fymas

New Member
Sep 16, 2014
3
0
I need a php script that will block all work possibilitys

Example:

Word: DevBest D evBest D ev Best ETC
Replace: You may not use this word
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,639
2,397
Here's a simple one.

PHP:
<?php
function censorWords($string) {
    $badwords = ['devbest', 'rastalulz', 'melody'];
    foreach ($badwords as $badword) {
        $string = preg_replace('/' . $badword . '/gi', '****', $string);
    }
    return $string;
}

echo censorWords('RastaLulz and Melody met on DevBest and he found out she was under-aged.');
//=> **** and **** met on **** and he found out she was under-aged.
?>

Doing what you want (where it can detect spaces etc) is fairly hard, so there's a pretty simple, basic one that you can use to modify.
 
Status
Not open for further replies.

Users who are viewing this thread

Top