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
https://forums.phpfreaks.com/topic/222339-match-words-from-an-array-to-a-string/
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?

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.