Last active
August 29, 2015 13:56
-
-
Save xbill82/8824481 to your computer and use it in GitHub Desktop.
Very fuzzy word-by-word match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Matches a string over the other in a fuzzy word-by-word fashion. | |
* The needle matches the haystack if the haystack contains all the words | |
* of the needle in any order. | |
* | |
* @param String $haystack The string to search in. | |
* @param String $needle The string that has to be searched for in the | |
* haystack. | |
* @return Boolean true if the needle matches the haystack, false | |
* otherwise. | |
*/ | |
static public function veryFuzzyMatch($haystack, $needle) { | |
$normalizedNeedle = self::toGenericKey($needle); | |
$normalizedStack = self::toGenericKey($haystack); | |
$found = true; | |
$splitNeedle = explode('-', $normalizedNeedle); | |
foreach ($splitNeedle as $word) { | |
if ( stripos($normalizedStack, $word) === false ) { | |
$found = false; | |
break; | |
} | |
} | |
return $found; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment