gardan06 Posted September 7, 2006 Share Posted September 7, 2006 for example:$string = "The quick brown fox jumps over the lazy dog";what command should i use to know whether the word "jumps" exists in that string? Quote Link to comment Share on other sites More sharing options...
emehrkay Posted September 7, 2006 Share Posted September 7, 2006 strpos would probalby work for you, but the pros would go with some regexhttp://us2.php.net/manual/en/function.strpos.phpcheck out the string functions in phphttp://us2.php.net/manual/en/ref.strings.php Quote Link to comment Share on other sites More sharing options...
hostfreak Posted September 7, 2006 Share Posted September 7, 2006 Here is one way:[code]<?php$word_filter = array( 'jump',);$post = 'The quick brown fox jumps over the lazy dog';function has_bad_words($post){ global $word_filter; $split = preg_split("#\s+#", $post, -1, PREG_SPLIT_NO_EMPTY); if (is_array($split)) { foreach ($split as $post_word) { if (in_array($post_word, $word_filter)) { return true; } } } return false;}if (has_bad_words($post)){ echo "The string contains jump";}else{ echo "The string doesn't contain jump";}?>[/code]Then you can add words to the array that you want to check for. Quote Link to comment Share on other sites More sharing options...
gardan06 Posted September 7, 2006 Author Share Posted September 7, 2006 thanks a lot :) 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.