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;
}

它返回一个我似乎无法从中获取字符串的数组。所以,我想从本质上获取结果,并将它们放在一个列表中,该列表是一个字符串数组,每个字符串都是单词,按照从最常见到最不常见的连续顺序排列。

4

1 回答 1

0

您可以使用strtok 函数。否则你可以用空格来分解字符串。我希望这会有所帮助:)

于 2013-08-11T10:27:48.770 回答