Jump to content

preg_match searching entire string


mike1313

Recommended Posts

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.

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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];
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.