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
https://forums.phpfreaks.com/topic/246490-preg_match-searching-entire-string/
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.

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

?>

Archived

This topic is now archived and is closed to further replies.

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