Skip to content

Instantly share code, notes, and snippets.

View Amegatron's full-sized avatar

Alexander Egorov Amegatron

View GitHub Profile
@Amegatron
Amegatron / popularWords
Created October 1, 2020 14:35
Test function for Dostavista
function popularWords($text, $amount = 5)
{
$top = [];
$words = preg_split('~[^[:alnum:]]+~is', strtolower($text), -1, PREG_SPLIT_NO_EMPTY);
foreach ($words as $word) {
if (!isset($top[$word])) {
$top[$word] = 0;
}
$top[$word]++;