gergy008 Posted December 21, 2010 Share Posted December 21, 2010 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! Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 21, 2010 Share Posted December 21, 2010 make the array. loop over the array, seeing whether each word is within the string. you can use strpos, stristr() or other functions to see if one string is within another one. Quote Link to comment Share on other sites More sharing options...
gergy008 Posted December 21, 2010 Author Share Posted December 21, 2010 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? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 21, 2010 Share Posted December 21, 2010 $words=array('naughty', 'words', 'go', 'here'); Quote Link to comment Share on other sites More sharing options...
gergy008 Posted December 21, 2010 Author Share Posted December 21, 2010 $words=array('naughty', 'words', 'go', 'here'); Thats what I did, I seperated the naughty words like that yet it's still not triggering. $words=array('*', '*', '*', '*', '*', '*', 'etc.'); Quote Link to comment Share on other sites More sharing options...
gergy008 Posted December 22, 2010 Author Share Posted December 22, 2010 Solved: Human error. It was seeing if $matched was false not $match. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.