Yapabileceğini söyleyebilirim:
- split the string into an array of words
- ile
explode
- ya da
preg_split
- karmaşıklığına bağlı olarak sizin kelime ayırıcılar için kabul edeceğiz
- use
array_filter to only keep the lines (i.e. words) you want
- geri arama işlevi, tüm geçerli olmayan-kelimeleri yanlış geri dönmek zorunda kalacak
- and, then, use
array_count_values on the resulting list of words
- Her kelime kelime dizisinde kaç kere saymak hangi
EDIT : ve sadece eğlence için, burada hızlı bir örnek:
Her şeyden önce, dize, o kelimelerin içine patladı alır:
$str = "will see you in London tomorrow and Kent the day after tomorrow";
$words = preg_split('/\s+/', $str, -1, PREG_SPLIT_NO_EMPTY);
var_dump($words);
Hangi seni alır:
array
0 => string 'will' (length=4)
1 => string 'see' (length=3)
2 => string 'you' (length=3)
3 => string 'in' (length=2)
4 => string 'London' (length=6)
5 => string 'tomorrow' (length=8)
6 => string 'and' (length=3)
7 => string 'Kent' (length=4)
8 => string 'the' (length=3)
9 => string 'day' (length=3)
10 => string 'after' (length=5)
11 => string 'tomorrow' (length=8)
Then, the filteting :
function filter_words($word) {
// a pretty simple filter ^^
if (strlen($word) >= 5) {
return true;
} else {
return false;
}
}
$words_filtered = array_filter($words, 'filter_words');
var_dump($words_filtered);
Hangi çıkışlar:
array
4 => string 'London' (length=6)
5 => string 'tomorrow' (length=8)
10 => string 'after' (length=5)
11 => string 'tomorrow' (length=8)
And, finally, the counting :
$counts = array_count_values($words_filtered);
var_dump($counts);
Ve sonuç:
array
'London' => int 1
'tomorrow' => int 2
'after' => int 1
Now, up to you to build up from here ;-)
Mainly, you'll have to work on :
- Ponctuation ile ilgilenen daha iyi bir patlama fonksiyonu, (or deal with that during filtering)
- Benimkinden daha ihtiyaçlarınızı daha iyi uyan bir "akıllı" filtreleme fonksiyonu,
Eğlenin!