<?php
$s1 = 'take of drink';
if(array_intersect(str_word_count($s1, 1), array('of')))
{
echo 'find';
}
else
{
echo 'not find';
}
?>
$s1 = 'take of drink';
if(array_intersect(str_word_count($s1, 1), array('of')))
{
echo 'find';
}
else
{
echo 'not find';
}
?>
$s1 = 'take of drink';
if(array_key_exists('of', array_flip(str_word_count($s1, 1))))
{
echo 'find';
}
else
{
echo 'not find';
}
?>
$str2 = "drink coffee";
$searchWord = 'of';
if(in_array($searchWord,str_word_count($str1,1))) echo "found in '{$str1}'";
if(in_array($searchWord,str_word_count($str2,1))) echo "found in '{$str2}'";
<?php
$str1 = "take of drink";
$str2 = "drink coffee";
$str3 = " of ";
function test_word($param,$param_sub)
{
if (strpos($param,$param_sub) !== false)
{
return "Found";
}
return "Not found";
}
echo test_word($str1,$str3)."\n";
echo test_word($str2,$str3);
?>
===================
---------- 程序调试 ----------Found
Not found
Output completed (0 sec consumed) - Normal Termination