<?php
$s1 = 'take of drink';
if(array_intersect(str_word_count($s1, 1), array('of')))
{
echo 'find';
}
else
{
echo 'not find';
}
?>

解决方案 »

  1.   

    或者<?php
    $s1 = 'take of drink';
    if(array_key_exists('of', array_flip(str_word_count($s1, 1))))
    {
    echo 'find';
    }
    else
    {
    echo 'not find';
    }
    ?>
      

  2.   

    正则:好象strpos()这个函数也可以,请你试一试。strpos(字符串,要找的字符串)如过他的返回值是  -1则没有这个字符
      

  3.   

    $str1 = "take of drink";
    $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}'";
      

  4.   


    <?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