0

配列から各文字列を呼び出そうとしています。ただし、このコードを使用して配列を生成しています。

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,0);
    return $keywords;
}

STRINGSを取得できないように見える配列を返します。したがって、本質的に結果を取得し、それらを文字列の配列であるリストに配置します。各文字列は単語であり、最も一般的なものから最も一般的でないものへと連続した順序で配置されます。

4

1 に答える 1