Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $bad = array("bad", "words", "here");
- $good = array("good", "words", "here");
- function noswear($string)
- {
- if ($string)
- {
- $bad = array("bad", "words");
- $good = array("good", "words");
- $newstring = str_replace($bad, $good, $string);
- return $newstring;
- }
- echo noswear("I see bad words coming!");
- function badWordsFilter($inputWord) {
- $badWords = Array("bad","words","here");
- for($i=0;$i<count($badWords);$i++) {
- if($badWords[$i] == strtolower($inputWord))
- return true;
- }
- return false;
- }
- if (badWordsFilter("bad")) {
- echo "Bad word was found";
- } else {
- echo "No bad words detected";
- }
- function badWordsFilter($inputWord) {
- $badWords = Array("bad","words","here");
- if(in_array(strtolower($inputWord), $badWords) ) {
- return true;
- }
- return false;
- }
- $wordsTransform = array(
- 'shit' => 'ship'
- );
- $string = "Rolling In The Deep by Adeln
- n
- There's a fire starting in my heartn
- Reaching a fever pitch, and it's bringing me out the darkn
- Finally I can see you crystal clearn
- Go ahead and sell me out and I'll lay your shit bare";
- $string = strtr($string, $wordsTransform);
- //
- // Written by Patrick Rauchfuss
- class String
- {
- public static function stritr(&$string, $from, $to = NULL)
- {
- if(is_string($from))
- $string = preg_replace("/b{$from}b/i", $to, $string);
- else if(is_array($from))
- {
- foreach ($from as $key => $val)
- self::stritr($string, $key, $val);
- }
- return preg_quote($string); // return and add a backslash to special characters
- }
- }
- $wordsTransform = array(
- 'shit' => 'ship'
- );
- String::stritr($string, $wordsTransform);
- $input_string = 'This Could be interesting but should it be? Perhaps this 'would' work; or couldn't it?';
- $bad_words = array('could', 'would', 'should');
- $good_words = array('might', 'will');
- function replace_words($matches){
- global $good_words;
- return $matches[1].$good_words[rand(0, count($good_words)-1)].$matches[3];
- }
- echo preg_replace_callback('/(^|b|s)('.implode('|', $bad_words).')(b|s|$)/i', 'replace_words', $input_string);
- /(START OR WORD_BOUNDARY OR WHITE_SPACE)(BAD_WORD)(WORD_BOUNDARY OR WHITE_SPACE OR END)/i
- global $good_words; <-- Makes the $good_words variable accessible from within the function
- $matches[1] <-- The word boundary before the matched word
- $matches[3] <-- The word boundary after the matched word
- $good_words[rand(0, count($good_words)-1] <-- Selects a random good word from $good_words
- echo preg_replace_callback(
- '/(^|b|s)('.implode('|', $bad_words).')(b|s|$)/i',
- function ($matches) use ($good_words){
- return $matches[1].$good_words[rand(0, count($good_words)-1)].$matches[3];
- },
- $input_string
- );
- function clean_string($input_string, $bad_words, $good_words){
- return preg_replace_callback(
- '/(^|b|s)('.implode('|', $bad_words).')(b|s|$)/i',
- function ($matches) use ($good_words){
- return $matches[1].$good_words[rand(0, count($good_words)-1)].$matches[3];
- },
- $input_string
- );
- }
- echo clean_string($input_string, $bad_words, $good_words);
- This will be interesting but might it be? Perhaps this 'will' work; or couldn't it?
- This might be interesting but might it be? Perhaps this 'might' work; or couldn't it?
- This might be interesting but will it be? Perhaps this 'will' work; or couldn't it?
- foreach($bad_words as $key=>$word){
- $bad_words[$key] = preg_quote($word);
- }
- b$h1tb <---Will not match
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement