例如 : 单词 man  字符串 :  now a man  ,then comes so many men here.计算 man 在字符串中出现的次数  men 也算进去 
相当于 man 在字符串中出现了两次.先谢谢了

解决方案 »

  1.   

    men也算进?
    那就没有办法了,除非你做一个字典,这个字有哪些也需要算进去的。
      

  2.   


    $str = 'now a man ,then comes so many men here.';
    $res = array_count_values(str_word_count($str, 1));
    echo $res['men'] + $res['man'];
      

  3.   


    function countWords($str)
    {
        preg_match_all("/m[ae]n/",$str,$matches);
        return count($matches);
    }
    $string = "now a man ,then comes so many men here.";
    echo countWords($string);
      

  4.   

    这样human,menu什么的也都会算进去的,在两边定下界才行
    function countWords($str)
    {
        preg_match_all("/[^a-zA-Z]m[ae]n[^a-zA-Z]/",$str,$matches);
        return count($matches);
    }
    $string = "now a man ,then comes so many men here.";
    echo countWords($string);