0
私はPHPで文字列の中で最も使用されている単語を見つけようとしています。歌詞ファイルは歌詞の文字列です。文字列内で最も使用されている単語を見つける方法PHP
//display the most used word in the lyrics file
$wordCount = str_word_count($lyrics);
$wordCountArray = array();
foreach($wordCount as $word){
if(!array_key_exists($word, $wordCountArray)){
$wordCountArray[$word] = 1;
}else{
$wordCountArray[$word] += 1;
}
}
arsort($wordCountArray);
print_r($wordCountArray[0]);
私はこのコードでエラーが発生していると私は働いていないかと思っています。私は実際の言葉ではなく数字を必要とします。
あなたの質問は何ですか? – Marcel
これは '$歌詞'が何であるかによって変わるかもしれません。例を挙げる必要があるかもしれません。 –
http://php.net/manual/en/function.substr-count.phpが役に立ちます – meen