redarrow Posted October 5, 2009 Share Posted October 5, 2009 advance thank you, is this code any good please before i add it to me project. This code is a example off finding the word wanted from the message box using the in_array function. if you no off a better solution then post your solution cheers. <?php $message="my name < is john "; $not_wanted=array( "<", ">", "<php", "?>", "lanuage='javascript'", "mysql=", "mysql_connect_database", "mysql_fetch_assoc", "mysql_fetch_array", "john" ); $mess=explode(' ',$message); foreach($mess as $messages){ if(in_array("$messages",$not_wanted)){ echo " \"$messages\" "; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/176496-solved-finding-words-and-non-wanted-charecters/ Share on other sites More sharing options...
.josh Posted October 5, 2009 Share Posted October 5, 2009 keep message as a string, loop through the unwanted array, use stripos Quote Link to comment https://forums.phpfreaks.com/topic/176496-solved-finding-words-and-non-wanted-charecters/#findComment-930359 Share on other sites More sharing options...
redarrow Posted October 5, 2009 Author Share Posted October 5, 2009 any reason please.... ANYMORE WELCOME. strpos way <?php $message="my name < is john "; $not_wanted=array( "<", ">", "<php", "?>", "lanuage='javascript'", "mysql=", "mysql_connect_database", "mysql_fetch_assoc", "mysql_fetch_array", "john" ); foreach($not_wanted as $go_away){ if(strpos($message,$go_away)){ echo $go_away; } } ?> in_array way..... <?php $message="my name < is john "; $not_wanted=array( "<", ">", "<php", "?>", "lanuage='javascript'", "mysql=", "mysql_connect_database", "mysql_fetch_assoc", "mysql_fetch_array", "john" ); $mess=explode(' ',$message); foreach($mess as $messages){ if(in_array("$messages",$not_wanted)){ echo " \"$messages\" "; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/176496-solved-finding-words-and-non-wanted-charecters/#findComment-930363 Share on other sites More sharing options...
redarrow Posted October 5, 2009 Author Share Posted October 5, 2009 Crayon Violent you are the man yeeeeee haaaaaaaaaaaaaa..... Quote Link to comment https://forums.phpfreaks.com/topic/176496-solved-finding-words-and-non-wanted-charecters/#findComment-930366 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.