I'm a bit impressed that none of the answers here that used strpos
, strstr
and similar functions mentioned Multibyte String Functions yet (2015-05-08).
Basically, if you're having trouble finding words with characters specific to some languages, such as German, French, Portuguese, Spanish, etc. (e.g.: ä, é, ô, ç, º, ñ), you may want to precede the functions with mb_
. Therefore, the accepted answer would use mb_strpos or mb_stripos (for case-insensitive matching) instead:
if (mb_strpos($a,'are') !== false) {
echo 'true';
}
If you cannot guarantee that all your data is 100% in UTF-8, you may want to use the mb_
functions.
A good article to understand why is The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) by Joel Spolsky.