mike1313 Posted September 5, 2011 Share Posted September 5, 2011 Alright basically what is want to do is take user input and I want it to check if the user asked if you like music? And I want to have so if you just entered, like music? it would return the same. So do you like music? and like music? would return the same result. So, Would preg_match be the best solution? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
xyph Posted September 6, 2011 Share Posted September 6, 2011 if( stripos($body, 'like music?') !== FALSE ) { // Found the phrase 'like music?' } http://php.net/manual/en/function.stripos.php Quote Link to comment Share on other sites More sharing options...
mike1313 Posted September 6, 2011 Author Share Posted September 6, 2011 That would work, but basically I need it so if they put music like? It would return the same results. So basically I need to search the entire string for two words like and music no matter what words come in between or what order they are in as long as they are in the same string. Quote Link to comment Share on other sites More sharing options...
xyph Posted September 7, 2011 Share Posted September 7, 2011 <?php $words = array( 'like', 'music' ); $matches = array(); foreach( $words as $key => $word ) { if( stripos( $string, $word ) ) $matches[] = $key; } echo 'Words found in $string: '; foreach( $matches as $match ) { echo $words[$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.