Reputation: 335
I have the below function to compare word in database with word the user searches for.It return true when there is a match and false if not. Some of the words have special /Unicode characters so we have to code in a way that it can fetch results when man uses normal alphabet counterparts of the special characters (e.g DB contains entry for Müller, then it can be fetched if user types Muller/muller/Müller/müller)
public function string_contains_word(string $string, string $word): bool {
// Handling non-ASCII characters.
$stringconv = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
$match_og = strpos(mb_strtolower($string), mb_strtolower($word)) !== false;
$match_conv = strpos(mb_strtolower($stringconv), mb_strtolower($word)) !== false;
$return_val = ($match_og !== false) ? $match_og : $match_conv;
return $return_val;
}
The evaluation works for most cases except for the below use case. If the database has an entry Yiǧit in a course, when user search for
I cannot visually see a difference between the 2 strings but when i run strcmp() on them
echo strcmp("Yiğit","Yiǧit");
it returns -3
Can anyone explain what the difference is and how can I reform the code so that the entry shows
Upvotes: 0
Views: 52