码迷,mamicode.com
首页 > Web开发 > 详细

PHP统计字符串里单词查询关键字

时间:2016-10-31 13:27:10      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:例子   整数   关键字   test   函数   result   res   ret   数组   

<?
function full_count_words($str) { 
    //返回完整数组,包含字符串里每个单词

    $words = str_word_count($str,1); 
    $result = array(); 
    foreach ($words as $w) { 
        $lw = strtolower($w); 
        //判断单词是否是第一次出现,是则设置为1,否则就增加1

        if (!(isset($result[$lw]))) { 
            $result[$lw] = 1; 
        } else { 
            $result[$lw]++; 
        } 
    } 
    return $result; 
}


?>


函数描述及例子

 

<? 
$test = "Good luck to you,good by! me to ,good ,good"; 
$wordcount =2881064151 full_count_words($test); 
//echo $wordcount[‘good‘];

print_r($wordcount); 
?>


查询关键字

 

PHP统计字符串里单词出现次数

PHP统计字符串里单词查询关键字

标签:例子   整数   关键字   test   函数   result   res   ret   数组   

原文地址:http://www.cnblogs.com/cbryge/p/6015365.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!