Jump to content

[SOLVED] A little preg_match help, if you will... :)


woolyg

Recommended Posts

I'm not sure but maybe I can help enough so you can search google for the rest.

 

What you need to do is be able to read a .txt file that has curse words in it. There is a function for that but not sure what it is.

 

Thankfully, once that's done you can check it with a variable quite easily:

 

$post = ////THE POST YOU ARE CHECKING

$cursewords = ////READ .TXT FILE AND STORE IN THIS VARIABLE

if (preg_match($cursewords,$post)){

echo "CURSE WORD DETECTED";

} else { echo "everybody is happy"; }

 

Hope that gets you closer to your answer.

Thanks,

 

I'm looking to do something like

 

$mystring = "Hello I'm looking for a word like word1 or word2";
$cursewords = array('word1', 'word2');

$pos = strpos($mystring, $cursewords);

echo $pos

 

.. but attempting to plug an array into strpos() isn't working. Has anyone dealt with this kind of string stuff before?

 

Thanks

WoolyG

You could loop through it.

 

$string = "Hello I'm looking for a word like word1 or word2";

$cursewords = array("word1","word2");

$found = 0;
foreach($cursewords as $word){
if(strpos($string, $word) !== false){
	$found++;
}
}

//if $found is greater then 0 then you have some bad words

i have something similar to the one projectfear posted this one blanks out the length of the word with * so if someone said the f word thats 4 stars if they said one with 8letters 8 stars etc etc.

 

function filter_lang($Input) {

    $obscenities = array("*+*++*+*","*-*-*-*-*", );

    foreach ($obscenities as $curse_word) {

        if (stristr(trim($Input),$curse_word)) { 
            $length = strlen($curse_word); 
            for ($i = 1; $i <= $length; $i++) { 
                $stars .= "*"; 
            } 
            $Input = eregi_replace($curse_word,$stars,trim($Input)); 
            $stars = ""; 
        } 

    }

    return $Input; 
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.