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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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; 
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.