脚本宝典收集整理的这篇文章主要介绍了最常用的文字用php,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP $text = "A very nice to tot to text. Something nice to think about if you're into text."; $words = str_word_count($text,1); $frequency = array_count_values($words); arsort($frequency); echo '<PRe>'; print_r($frequency); echo '</pre>'; ?>
您可以将此文件stop_words.txt用作主要停用词文件,也可以创建自己的文件.
function extract_common_words($string,$stop_words,$max_count = 5) { $string = preg_replace('/ss+/i','',$string); $string = trim($string); // trim the string $string = preg_replace('/[^a-zA-Z -]/',$string); // only take alphabet characters,but keep the spaces and dashes too… $string = strtolower($string); // make IT lowercase preg_match_all('/\b.*?\b/i',$string,$match_words); $match_words = $match_words[0]; foreach ( $match_words as $key => $item ) { if ( $item == '' || in_array(strtolower($item),$stop_words) || strlen($item) <= 3 ) { unset($match_words[$key]); } } $word_count = str_word_count( implode(" ",$match_words),1); $frequency = array_count_values($word_count); arsort($frequency); //arsort($word_count_arr); $keywords = array_slice($frequency,$max_count); return $keywords; }
以上是脚本宝典为你收集整理的最常用的文字用php全部内容,希望文章能够帮你解决最常用的文字用php所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。