文字列内の TOP または BRITISH を検索するには
<?php
$var1 = "Top of British";
$var2 = "Welcome to British, the TOP country in the world";
$var1 = strtolower($var1);
$var2 = strtolower($var2);
if (strpos($var1, 'top') && strpos($var1, 'british')) {
echo "Either the word TOP or the word BRITISH was found in string 1";
}
?>
より一般的に文字列 2 の単語を文字列 1 の単語と一致させます
<?php
$var1 = explode(' ', strtolower("Top of British"));
$var2 = "Welcome to British, the TOP country in the world";
$var2 = strtolower($var2);
foreach($var1 as $needle) if (strpos($var2, $needle)) echo "At least one word in str1 was found in str 2";
?>