Jump to content

Match words from an array to a string?


gergy008

Recommended Posts

Dead simple, I know it is but I'm still a little newbie. I have this chat box, and I don't want people to be able to swear in it so I need help making a function where you call the string as an argument and it returns true if the string has any words from an array in it, Even if the word is walking and not just walk. If it's true I can replace the entire string with something else.

 

Can someone tell me what functions I need? I prefer you didn't do it all for me I need to learn  ;)

 

Thanks in advance!

Link to comment
Share on other sites

I made this:

 

$text = $_POST['text'];
$words=array('naughty words go here');
$match=false;
foreach($words as $word){
	$test=strpos($text, $word);
	if($test==true){
		$match=true;
	}
}

 

But yet $match remains false, So it isn't replacing the string... Does anyone know why it won't trigger?

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.